예제 #1
0
        private void InitConfigurationParameters(Camera cam)
        {
            this.SuspendLayout();
            tableLayoutPanel1.SuspendLayout();

            // reset view
            tableLayoutPanel1.Controls.Clear();
            tableLayoutPanel1.RowStyles.Clear();

            int currentRow = 0;

            AddHeadingRow(currentRow);

            List <MetriCam2.Camera.ParamDesc> parameters    = new List <MetriCam2.Camera.ParamDesc>();
            List <MetriCam2.Camera.ParamDesc> allParameters = cam.GetParameters();

            if (VisibleParameters != null)
            {
                foreach (var item in allParameters)
                {
                    if (VisibleParameters.Contains(item.Name))
                    {
                        parameters.Add(item);
                    }
                }
            }
            else
            {
                parameters = allParameters;
            }

            parameters.Sort(new ParamDescComparer());

            ContainsOneOrMoreWritableParameters = false;
            int contentHeight = HeadingFont.Height * 2;

            foreach (var paramDesc in parameters)
            {
                currentRow++;
                tableLayoutPanel1.RowCount = currentRow + 1;

                int rowHeight = LabelFont.Height * 2;
                if (paramDesc is MetriCam2.Camera.MultiFileParamDesc)
                {
                    rowHeight = MultiFileSelector.StandardHeight + 8;
                }
                tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, rowHeight));
                contentHeight += rowHeight;

                tableLayoutPanel1.Controls.Add(CreateNameLabel(paramDesc), COL_PARAM_NAME, currentRow);

                // Build a suitable control for the current parameter
                // Parameter with a value range
                if (paramDesc is MetriCam2.Camera.IRangeParamDesc)
                {
                    if (paramDesc is MetriCam2.Camera.RangeParamDesc <int> )
                    {
                        Slider scrollbarValue = CreateSlider((MetriCam2.Camera.RangeParamDesc <int>)paramDesc, currentRow);
                        tableLayoutPanel1.Controls.Add(scrollbarValue, COL_PARAM_VAL, currentRow);
                        Label unit = CreateUnitLabel(paramDesc);
                        tableLayoutPanel1.Controls.Add(unit, COL_PARAM_UNIT, currentRow);
                        if (scrollbarValue.Enabled)
                        {
                            ContainsOneOrMoreWritableParameters = true;
                        }
                    }
                    else if (paramDesc is MetriCam2.Camera.RangeParamDesc <float> )
                    {
                        NumericUpDown upDownValue = CreateNumericUpDown((MetriCam2.Camera.RangeParamDesc <float>)paramDesc, currentRow);
                        tableLayoutPanel1.Controls.Add(upDownValue, COL_PARAM_VAL, currentRow);
                        Label unit = CreateUnitLabel(paramDesc);
                        tableLayoutPanel1.Controls.Add(unit, COL_PARAM_UNIT, currentRow);
                        if (upDownValue.Enabled)
                        {
                            ContainsOneOrMoreWritableParameters = true;
                        }
                    }
                    else
                    {
                        TextBox textBoxValue = CreateTextBox(paramDesc, currentRow);
                        tableLayoutPanel1.Controls.Add(textBoxValue, COL_PARAM_VAL, currentRow);
                        Label unit = CreateUnitLabel(paramDesc);
                        tableLayoutPanel1.Controls.Add(unit, COL_PARAM_UNIT, currentRow);
                        if (textBoxValue.Enabled)
                        {
                            ContainsOneOrMoreWritableParameters = true;
                        }
                    }

                    continue;
                }

                // Parameter with a list of values
                if (paramDesc is MetriCam2.Camera.IListParamDesc)
                {
                    ComboBox comboBoxValue = CreateComboBox(paramDesc as Camera.IListParamDesc, currentRow);
                    tableLayoutPanel1.Controls.Add(comboBoxValue, COL_PARAM_VAL, currentRow);
                    Label unit = CreateUnitLabel(paramDesc);
                    tableLayoutPanel1.Controls.Add(unit, COL_PARAM_UNIT, currentRow);
                    if (comboBoxValue.Enabled)
                    {
                        ContainsOneOrMoreWritableParameters = true;
                    }

                    continue;
                }

                if (paramDesc is MetriCam2.Camera.MultiFileParamDesc)
                {
                    MultiFileSelector fileSelector = CreateMultiFileSelector(paramDesc as MetriCam2.Camera.MultiFileParamDesc, currentRow);
                    tableLayoutPanel1.Controls.Add(fileSelector, COL_PARAM_VAL, currentRow);
                    Label unit = CreateUnitLabel(paramDesc);
                    tableLayoutPanel1.Controls.Add(unit, COL_PARAM_UNIT, currentRow);
                    if (fileSelector.Enabled)
                    {
                        ContainsOneOrMoreWritableParameters = true;
                    }

                    continue;
                }

                // Parameter of type bool
                if (paramDesc is MetriCam2.Camera.ParamDesc <bool> )
                {
                    // TODO: build a checkbox
                    CheckBox checkBoxValue = CreateCheckBox(paramDesc as Camera.ParamDesc <bool>, currentRow);
                    tableLayoutPanel1.Controls.Add(checkBoxValue, COL_PARAM_VAL, currentRow);
                    Label unit = CreateUnitLabel(paramDesc);
                    tableLayoutPanel1.Controls.Add(unit, COL_PARAM_UNIT, currentRow);
                    if (checkBoxValue.Enabled)
                    {
                        ContainsOneOrMoreWritableParameters = true;
                    }

                    continue;
                }

                // Parameter with a primitive value (e.g. int, string, float, ...)
                if (paramDesc is MetriCam2.Camera.ParamDesc)
                {
                    // build a text box
                    TextBox textBoxValue = CreateTextBox(paramDesc, currentRow);
                    tableLayoutPanel1.Controls.Add(textBoxValue, COL_PARAM_VAL, currentRow);
                    Label unit = CreateUnitLabel(paramDesc);
                    tableLayoutPanel1.Controls.Add(unit, COL_PARAM_UNIT, currentRow);

                    if (textBoxValue.Enabled)
                    {
                        ContainsOneOrMoreWritableParameters = true;
                    }

                    continue;
                }

                tableLayoutPanel1.ResumeLayout();
                this.ResumeLayout();
                throw new TypeAccessException("No suitable control found for this parameter type.");
            }
            tableLayoutPanel1.RowCount++;

            // Update control size
            this.Height      = contentHeight + 2; // add some space for the borders. 2px is the minimum on my (Hannes) Win7 PC
            this.MinimumSize = new Size(this.Width, this.Height);

            tableLayoutPanel1.ResumeLayout();
            this.ResumeLayout();
        }
예제 #2
0
        private void InitConfigurationParameters(Camera cam)
        {
            this.SuspendLayout();
            tableLayoutPanel1.SuspendLayout();

            // reset view
            tableLayoutPanel1.Controls.Clear();
            tableLayoutPanel1.RowStyles.Clear();

            int currentRow = 0;

            AddHeadingRow(currentRow);

            List <Camera.ParamDesc> parameters    = new List <Camera.ParamDesc>();
            List <Camera.ParamDesc> allParameters = cam.GetParameters();

            if (VisibleParameters != null)
            {
                foreach (var item in allParameters)
                {
                    if (VisibleParameters.Contains(item.Name))
                    {
                        parameters.Add(item);
                    }
                }
            }
            else
            {
                parameters = allParameters;
            }

            parameters.Sort(new ParamDescComparer());

            ContainsOneOrMoreWritableParameters = false;
            int contentHeight = HeadingFont.Height * 2;

            foreach (var paramDesc in parameters)
            {
                currentRow++;
                tableLayoutPanel1.RowCount = currentRow + 1;

                int rowHeight = LabelFont.Height * 2;
                if (paramDesc is Camera.MultiFileParamDesc)
                {
                    rowHeight = MultiFileSelector.StandardHeight + 8;
                }
                tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, rowHeight));
                contentHeight += rowHeight;

                tableLayoutPanel1.Controls.Add(CreateNameLabel(paramDesc), COL_PARAM_NAME, currentRow);

                // Build a suitable control for the current parameter
                // Parameter with a value range
                if (paramDesc is Camera.IRangeParamDesc)
                {
                    if (paramDesc is Camera.RangeParamDesc <int> )
                    {
                        Slider scrollbarValue = CreateSlider((Camera.RangeParamDesc <int>)paramDesc, currentRow);
                        tableLayoutPanel1.Controls.Add(scrollbarValue, COL_PARAM_VAL, currentRow);
                        Label unit = CreateUnitLabel(paramDesc);
                        tableLayoutPanel1.Controls.Add(unit, COL_PARAM_UNIT, currentRow);
                        if (scrollbarValue.Enabled)
                        {
                            ContainsOneOrMoreWritableParameters = true;
                        }
                        scrollbarValue.ValueChanged += (sender, e) =>
                        {
                            string parameterValue = scrollbarValue.Value.ToString(CultureInfo.InvariantCulture);
                            try
                            {
                                Camera.SetParameter(paramDesc.Name, parameterValue);
                            }
                            catch (SettingsCombinationNotSupportedException)
                            {
                                ShowMessageBoxCombinationOfSettingsNotSupported();
                            }
                        };
                    }
                    else if (paramDesc is Camera.RangeParamDesc <float> )
                    {
                        NumericUpDown upDownValue = CreateNumericUpDown((Camera.RangeParamDesc <float>)paramDesc, currentRow);
                        tableLayoutPanel1.Controls.Add(upDownValue, COL_PARAM_VAL, currentRow);
                        Label unit = CreateUnitLabel(paramDesc);
                        tableLayoutPanel1.Controls.Add(unit, COL_PARAM_UNIT, currentRow);
                        if (upDownValue.Enabled)
                        {
                            ContainsOneOrMoreWritableParameters = true;
                        }

                        upDownValue.ValueChanged += (sender, e) =>
                        {
                            string parameterValue = upDownValue.Value.ToString(CultureInfo.InvariantCulture);
                            try
                            {
                                Camera.SetParameter(paramDesc.Name, parameterValue);
                            }
                            catch (SettingsCombinationNotSupportedException)
                            {
                                ShowMessageBoxCombinationOfSettingsNotSupported();
                            }
                        };
                    }
                    else
                    {
                        TextBox textBoxValue = CreateTextBox(paramDesc, currentRow);
                        tableLayoutPanel1.Controls.Add(textBoxValue, COL_PARAM_VAL, currentRow);
                        Label unit = CreateUnitLabel(paramDesc);
                        tableLayoutPanel1.Controls.Add(unit, COL_PARAM_UNIT, currentRow);
                        if (textBoxValue.Enabled)
                        {
                            ContainsOneOrMoreWritableParameters = true;
                        }
                    }

                    continue;
                }

                // Parameter with a list of values
                if (paramDesc is Camera.IListParamDesc)
                {
                    ComboBox comboBoxValue = CreateComboBox(paramDesc as Camera.IListParamDesc, currentRow);
                    tableLayoutPanel1.Controls.Add(comboBoxValue, COL_PARAM_VAL, currentRow);
                    Label unit = CreateUnitLabel(paramDesc);
                    tableLayoutPanel1.Controls.Add(unit, COL_PARAM_UNIT, currentRow);
                    if (comboBoxValue.Enabled)
                    {
                        ContainsOneOrMoreWritableParameters = true;
                    }

                    if (paramDesc is Camera.ListParamDesc <Point2i> ||
                        paramDesc is Camera.ListParamDesc <int> ||
                        (paramDesc as Camera.IListParamDesc).GetListType().IsEnum)
                    {
                        comboBoxValue.SelectedValueChanged += (sender, e) =>
                        {
                            object parameterValue;

                            if (paramDesc is Camera.ListParamDesc <Point2i> )
                            {
                                parameterValue = ResolutionToPoint2i(comboBoxValue.SelectedItem as string);
                            }
                            else if (paramDesc is Camera.ListParamDesc <int> )
                            {
                                parameterValue = int.Parse(comboBoxValue.SelectedItem as string);
                            }
                            else // Enum
                            {
                                parameterValue = Enum.Parse((paramDesc as Camera.IListParamDesc).GetListType(), comboBoxValue.SelectedItem as string);
                            }

                            try
                            {
                                Camera.SetParameter(paramDesc.Name, parameterValue);
                            }
                            catch (SettingsCombinationNotSupportedException)
                            {
                                ShowMessageBoxCombinationOfSettingsNotSupported();
                            }
                        };
                    }

                    continue;
                }

                if (paramDesc is Camera.MultiFileParamDesc)
                {
                    MultiFileSelector fileSelector = CreateMultiFileSelector(paramDesc as Camera.MultiFileParamDesc, currentRow);
                    tableLayoutPanel1.Controls.Add(fileSelector, COL_PARAM_VAL, currentRow);
                    Label unit = CreateUnitLabel(paramDesc);
                    tableLayoutPanel1.Controls.Add(unit, COL_PARAM_UNIT, currentRow);
                    if (fileSelector.Enabled)
                    {
                        ContainsOneOrMoreWritableParameters = true;
                    }
                    fileSelector.PropertyChanged += (sender, e) =>
                    {
                        Camera.SetParameter(paramDesc.Name, fileSelector.SelectedFiles);
                    };

                    continue;
                }

                // Parameter of type bool
                if (paramDesc is Camera.ParamDesc <bool> )
                {
                    // TODO: build a checkbox
                    CheckBox checkBoxValue = CreateCheckBox(paramDesc as Camera.ParamDesc <bool>, currentRow);
                    tableLayoutPanel1.Controls.Add(checkBoxValue, COL_PARAM_VAL, currentRow);
                    Label unit = CreateUnitLabel(paramDesc);
                    tableLayoutPanel1.Controls.Add(unit, COL_PARAM_UNIT, currentRow);
                    if (checkBoxValue.Enabled)
                    {
                        ContainsOneOrMoreWritableParameters = true;
                    }

                    checkBoxValue.CheckStateChanged += (sender, e) =>
                    {
                        string parameterValue = checkBoxValue.Checked.ToString(CultureInfo.InvariantCulture);
                        string parameterName  = checkBoxValue.Name.Replace(VALUE_SUFFIX, string.Empty);
                        Dictionary <string, object> keyValues = new Dictionary <string, object>();
                        keyValues.Add(parameterName, parameterValue);

                        try
                        {
                            Camera.SetParameters(keyValues);
                        }
                        catch (SettingsCombinationNotSupportedException)
                        {
                            ShowMessageBoxCombinationOfSettingsNotSupported();
                        }
                    };

                    continue;
                }

                // Parameter with a primitive value (e.g. int, string, float, ...)
                if (paramDesc is Camera.ParamDesc)
                {
                    // build a text box
                    TextBox textBoxValue = CreateTextBox(paramDesc, currentRow);
                    tableLayoutPanel1.Controls.Add(textBoxValue, COL_PARAM_VAL, currentRow);
                    Label unit = CreateUnitLabel(paramDesc);
                    tableLayoutPanel1.Controls.Add(unit, COL_PARAM_UNIT, currentRow);

                    if (textBoxValue.Enabled)
                    {
                        ContainsOneOrMoreWritableParameters = true;
                    }

                    continue;
                }

                tableLayoutPanel1.ResumeLayout();
                this.ResumeLayout();
                throw new TypeAccessException("No suitable control found for this parameter type.");
            }
            tableLayoutPanel1.RowCount++;

            // Update control size
            this.Height      = contentHeight + 2; // add some space for the borders. 2px is the minimum on my (Hannes) Win7 PC
            this.MinimumSize = new Size(this.Width, this.Height);

            tableLayoutPanel1.ResumeLayout();
            this.ResumeLayout();
        }