Exemplo n.º 1
0
        private ParameterInputDialog(ParameterInfo[] paramInfo, Object[] paramList)
        {
            InitializeComponent();

            int panelsHeight = 0;

            _paramValue = new object[paramInfo.Length];

            _paramInfo  = paramInfo;
            _paramPanel = new ParamInputPanel[paramInfo.Length];

            for (int i = 0; i < paramInfo.Length; i++)
            {
                ParamInputPanel panel = CreatePanelForParameter(
                    paramInfo[i],
                    (paramList == null || i >= paramList.Length) ? null : paramList[i]);
                parameterInputPanel.Controls.Add(panel);
                panel.Location = new Point(0, i * panel.Height);
                _paramPanel[i] = panel;

                panelsHeight += panel.Height;
            }

            Height = panelsHeight + 100;
        }
Exemplo n.º 2
0
        private void okButton_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < _paramInfo.Length; i++)
            {
                ParamInputPanel panel = _paramPanel[i];
                Object          value = panel.GetValue();
                if (value == null)
                {
                    MessageBox.Show(Properties.StringTable.ParameterIsInvalid, panel.Name);
                    return;
                }

                _paramValue[i] = value;
            }

            _sucessed = true;
            Close();
        }
Exemplo n.º 3
0
        private void okButton_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < _paramInfo.Length; i++)
            {
                ParamInputPanel panel = _paramPanel[i];
                Object          value = panel.GetValue();
                if (value == null)
                {
                    MessageBox.Show(String.Format("Parameter {0} is invalid.", panel.Name));
                    return;
                }

                _paramValue[i] = value;
            }

            _sucessed = true;
            Close();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create a panel for the specific parameter
        /// </summary>
        /// <param name="param">the parameter to create panel for</param>
        /// <param name="defaultValue">The default value for the parameter</param>
        /// <returns>the panel</returns>
        private static ParamInputPanel CreatePanelForParameter(ParameterInfo param, object defaultValue)
        {
            ParamInputPanel panel = new ParamInputPanel();

            panel.Height = 50;
            panel.Width  = 400;
            Point textBoxStart = new Point(100, 10);

            #region add the label for the parameter
            Label paramNameLabel = new Label();
            paramNameLabel.AutoSize = true;
            panel.Controls.Add(paramNameLabel);
            paramNameLabel.Location = new Point(10, textBoxStart.Y);
            #endregion

            if (param == null)
            { // a generic parameter
                GenericParameter p = defaultValue as GenericParameter;

                paramNameLabel.Text = "";

                String[] options = Array.ConvertAll <Type, String>(p.AvailableTypes, delegate(Type t) { return(t.Name); });
                ComboBox combo   = new ComboBox();
                panel.Controls.Add(combo);
                combo.Location = textBoxStart;
                combo.Items.AddRange(options);
                combo.SelectedIndex    = Array.FindIndex <String>(options, p.SelectedType.ToString().Equals);
                panel.GetParamFunction =
                    delegate()
                {
                    return
                        (new GenericParameter(
                             p.AvailableTypes[Array.FindIndex <String>(options, combo.Text.ToString().Equals)],
                             p.AvailableTypes));
                };
            }
            else
            {
                Type paramType = param.ParameterType;
                paramNameLabel.Text = String.Format("{0}:", ParseParameterName(param));

                if (paramType.IsEnum)
                {
                    ComboBox combo = new ComboBox();
                    panel.Controls.Add(combo);
                    combo.Location = textBoxStart;
                    combo.Items.AddRange(Enum.GetNames(paramType));
                    combo.SelectedIndex = 0;
                    combo.Width         = 240;

                    panel.GetParamFunction =
                        delegate
                    {
                        return(Enum.Parse(paramType, combo.SelectedItem.ToString(), true));
                    };
                }
                else if (paramType == typeof(bool))
                {
                    ComboBox combo = new ComboBox();
                    panel.Controls.Add(combo);
                    combo.Location = textBoxStart;
                    combo.Items.AddRange(new String[] { "True", "False" });
                    combo.SelectedIndex    = 0;
                    panel.GetParamFunction =
                        delegate()
                    {
                        return(combo.SelectedItem.ToString().Equals("True"));
                    };
                }
                else if (paramType == typeof(UInt64) || paramType == typeof(int) || paramType == typeof(double))
                {
                    //Create inpout box for the int paramater
                    TextBox inputTextBox = new TextBox();
                    panel.Controls.Add(inputTextBox);
                    inputTextBox.Location = textBoxStart;
                    inputTextBox.Text     = defaultValue == null ? "0" : defaultValue.ToString();

                    panel.GetParamFunction =
                        delegate()
                    {
                        return(Convert.ChangeType(inputTextBox.Text, paramType));
                    };
                }
                else if (paramType == typeof(MCvScalar))
                {
                    TextBox[] inputBoxes = new TextBox[4];
                    int       boxWidth   = 40;

                    //Create input boxes for the scalar value
                    for (int i = 0; i < inputBoxes.Length; i++)
                    {
                        inputBoxes[i] = new TextBox();
                        panel.Controls.Add(inputBoxes[i]);
                        inputBoxes[i].Location = new Point(textBoxStart.X + i * (boxWidth + 5), textBoxStart.Y);
                        inputBoxes[i].Width    = boxWidth;
                        inputBoxes[i].Text     = "0.0";
                    }
                    panel.GetParamFunction =
                        delegate()
                    {
                        double[] values = new double[4];
                        for (int i = 0; i < inputBoxes.Length; i++)
                        {
                            values[i] = Convert.ToDouble(inputBoxes[i].Text);
                        }
                        return(new MCvScalar(values[0], values[1], values[2], values[3]));
                    };
                }
                else if (paramType == typeof(PointF))
                {
                    TextBox[] inputBoxes = new TextBox[2];
                    int       boxWidth   = 40;

                    //Create input boxes for the scalar value
                    for (int i = 0; i < 2; i++)
                    {
                        inputBoxes[i] = new TextBox();
                        panel.Controls.Add(inputBoxes[i]);
                        inputBoxes[i].Location = new Point(textBoxStart.X + i * (boxWidth + 5), textBoxStart.Y);
                        inputBoxes[i].Width    = boxWidth;
                        inputBoxes[i].Text     = "0.0";
                    }
                    panel.GetParamFunction =
                        delegate()
                    {
                        float[] values = new float[inputBoxes.Length];
                        for (int i = 0; i < inputBoxes.Length; i++)
                        {
                            values[i] = Convert.ToSingle(inputBoxes[i].Text);
                        }
                        return(new PointF(values[0], values[1]));
                    };
                }
                else if (paramType.GetInterface("IColor") == typeof(IColor))
                {
                    IColor t = Activator.CreateInstance(paramType) as IColor;
                    //string[] channelNames = ReflectColorType.GetNamesOfChannels(t);
                    TextBox[] inputBoxes = new TextBox[t.Dimension];
                    int       boxWidth   = 40;

                    //Create input boxes for the scalar value
                    for (int i = 0; i < inputBoxes.Length; i++)
                    {
                        inputBoxes[i] = new TextBox();
                        panel.Controls.Add(inputBoxes[i]);
                        inputBoxes[i].Location = new Point(textBoxStart.X + i * (boxWidth + 5), textBoxStart.Y);
                        inputBoxes[i].Width    = boxWidth;
                        inputBoxes[i].Text     = "0.0";
                    }
                    panel.GetParamFunction =
                        delegate()
                    {
                        double[] values = new double[4];
                        for (int i = 0; i < inputBoxes.Length; i++)
                        {
                            values[i] = Convert.ToDouble(inputBoxes[i].Text);
                        }
                        IColor color = Activator.CreateInstance(paramType) as IColor;
                        color.MCvScalar = new MCvScalar(values[0], values[1], values[2], values[3]);
                        return(color);
                    };
                }
                else
                {
                    throw new NotSupportedException(String.Format(Properties.StringTable.ParameterTypeIsNotSupported, paramType.Name));
                }
            }
            return(panel);
        }
Exemplo n.º 5
0
      /// <summary>
      /// Create a panel for the specific parameter
      /// </summary>
      /// <param name="param">the parameter to create panel for</param>
      /// <param name="defaultValue">The default value for the parameter</param>
      /// <returns>the panel</returns>
      private static ParamInputPanel CreatePanelForParameter(ParameterInfo param, object defaultValue)
      {
         ParamInputPanel panel = new ParamInputPanel();
         panel.Height = 50;
         panel.Width = 400;
         Point textBoxStart = new Point(100, 10);

         #region add the label for the parameter
         Label paramNameLabel = new Label();
         paramNameLabel.AutoSize = true;
         panel.Controls.Add(paramNameLabel);
         paramNameLabel.Location = new Point(10, textBoxStart.Y);
         #endregion

         if (param == null)
         {  // a generic parameter

            GenericParameter p = defaultValue as GenericParameter;

            paramNameLabel.Text = "";

            String[] options = Array.ConvertAll<Type, String>(p.AvailableTypes, delegate(Type t) { return t.Name; }); 
            ComboBox combo = new ComboBox();
            panel.Controls.Add(combo);
            combo.Location = textBoxStart;
            combo.Items.AddRange(options);
            combo.SelectedIndex = Array.FindIndex<String>(options, p.SelectedType.ToString().Equals);
            panel.GetParamFunction =
                delegate()
                {
                   return
                      new GenericParameter(
                       p.AvailableTypes[Array.FindIndex<String>(options, combo.Text.ToString().Equals)],
                       p.AvailableTypes);
                };
         }
         else
         {
            Type paramType = param.ParameterType;
            paramNameLabel.Text = String.Format("{0}:", ParseParameterName(param));

            if (paramType.IsEnum)
            {
               ComboBox combo = new ComboBox();
               panel.Controls.Add(combo);
               combo.Location = textBoxStart;
               combo.Items.AddRange(Enum.GetNames(paramType));
               combo.SelectedIndex = 0;

               panel.GetParamFunction =
                   delegate
                   {
                      return Enum.Parse(paramType, combo.SelectedItem.ToString(), true);
                   };
            }
            else if (paramType == typeof(bool))
            {
               ComboBox combo = new ComboBox();
               panel.Controls.Add(combo);
               combo.Location = textBoxStart;
               combo.Items.AddRange(new String[] { "True", "False" });
               combo.SelectedIndex = 0;
               panel.GetParamFunction =
                   delegate()
                   {
                      return combo.SelectedItem.ToString().Equals("True");
                   };
            }
            else if (paramType == typeof(UInt64) || paramType == typeof(int) || paramType == typeof(double))
            {
               //Create inpout box for the int paramater
               TextBox inputTextBox = new TextBox();
               panel.Controls.Add(inputTextBox);
               inputTextBox.Location = textBoxStart;
               inputTextBox.Text = defaultValue == null ? "0" : defaultValue.ToString();

               panel.GetParamFunction =
                   delegate()
                   {
                      return Convert.ChangeType(inputTextBox.Text, paramType);
                   };
            }
            else if (paramType == typeof(MCvScalar))
            {
               TextBox[] inputBoxes = new TextBox[4];
               int boxWidth = 40;

               //Create input boxes for the scalar value
               for (int i = 0; i < inputBoxes.Length; i++)
               {
                  inputBoxes[i] = new TextBox();
                  panel.Controls.Add(inputBoxes[i]);
                  inputBoxes[i].Location = new Point(textBoxStart.X + i * (boxWidth + 5), textBoxStart.Y);
                  inputBoxes[i].Width = boxWidth;
                  inputBoxes[i].Text = "0.0";
               }
               panel.GetParamFunction =
                   delegate()
                   {
                      double[] values = new double[4];
                      for (int i = 0; i < inputBoxes.Length; i++)
                      {
                         values[i] = Convert.ToDouble(inputBoxes[i].Text);
                      }
                      return new MCvScalar(values[0], values[1], values[2], values[3]);
                   };
            }
            else if (paramType.GetInterface("IColor") == typeof(IColor))
            {
               IColor t = Activator.CreateInstance(paramType) as IColor;
               //string[] channelNames = ReflectColorType.GetNamesOfChannels(t);
               TextBox[] inputBoxes = new TextBox[t.Dimension];
               int boxWidth = 40;

               //Create input boxes for the scalar value
               for (int i = 0; i < inputBoxes.Length; i++)
               {
                  inputBoxes[i] = new TextBox();
                  panel.Controls.Add(inputBoxes[i]);
                  inputBoxes[i].Location = new Point(textBoxStart.X + i * (boxWidth + 5), textBoxStart.Y);
                  inputBoxes[i].Width = boxWidth;
                  inputBoxes[i].Text = "0.0";
               }
               panel.GetParamFunction =
                   delegate()
                   {
                      double[] values = new double[4];
                      for (int i = 0; i < inputBoxes.Length; i++)
                      {
                         values[i] = Convert.ToDouble(inputBoxes[i].Text);
                      }
                      IColor color = Activator.CreateInstance(paramType) as IColor;
                      color.MCvScalar = new MCvScalar(values[0], values[1], values[2], values[3]);
                      return color;
                   };
            }
            else
            {
               throw new NotSupportedException(String.Format(Properties.StringTable.ParameterTypeIsNotSupported, paramType.Name));
            }
         }
         return panel;
      }