예제 #1
0
        public iParam clone()
        {
            ParamBoolArr clone = new ParamBoolArr(name, group, parentSet, desc, stdValue, options);

            clone.stdValue = stdValue;

            clone.minValue = minValue;
            clone.maxValue = maxValue;

            clone.values = new bool[values.Length];
            for (int i = 0; i < values.Length; i++)
            {
                clone.values[i] = values[i];
            }

            return(clone);
        }
예제 #2
0
        public iParam addParameter <T>(string name, string group, string desc, string minValue, string maxValue, string stdValue, string[] options, Param.ParamSideButton[] buttons)
        {
            lock (lockParameters) {
                // check if a parameter with that name already exists, return without adding if this is the case
                if (getParameter(name) != null)
                {
                    logger.Warn("A parameter with the name '" + name + "' already exists in parameter set '" + paramSetName + "', not added.");
                    return(null);
                }

                // retrieve the type of parameter
                Type paramType = typeof(T);

                // only allow for side buttons on string types
                if (buttons != null && buttons.Length != 0)
                {
                    if (!(paramType == typeof(ParamString) || paramType == typeof(string) || paramType == typeof(String)))
                    {
                        logger.Warn("Discarding extra buttons for parameter '" + name + "' in parameter set '" + paramSetName + "', extra buttons are only allowed for parameters of the String-type");
                        buttons = null;
                    }
                    else if (paramType == typeof(ParamFileString))
                    {
                        logger.Warn("Discarding extra buttons for parameter '" + name + "' in parameter set '" + paramSetName + "', only a browse button will be added for a parameter of the type FileString");
                        buttons = null;
                    }
                }

                // create a new parameter and transfer the properties
                iParam param = null;
                if (paramType == typeof(ParamBool) || paramType == typeof(bool) || paramType == typeof(Boolean))
                {
                    param = new ParamBool(name, group, this, desc, stdValue, options);
                }
                else if (paramType == typeof(ParamInt) || paramType == typeof(int))
                {
                    param = new ParamInt(name, group, this, desc, stdValue, options);
                }
                else if (paramType == typeof(ParamDouble) || paramType == typeof(double))
                {
                    param = new ParamDouble(name, group, this, desc, stdValue, options);
                }
                else if (paramType == typeof(ParamBoolArr) || paramType == typeof(bool[]) || paramType == typeof(Boolean[]))
                {
                    param = new ParamBoolArr(name, group, this, desc, stdValue, options);
                }
                else if (paramType == typeof(ParamIntArr) || paramType == typeof(int[]))
                {
                    param = new ParamIntArr(name, group, this, desc, stdValue, options);
                }
                else if (paramType == typeof(ParamDoubleArr) || paramType == typeof(double[]))
                {
                    param = new ParamDoubleArr(name, group, this, desc, stdValue, options);
                }
                else if (paramType == typeof(ParamBoolMat) || paramType == typeof(bool[][]) || paramType == typeof(Boolean[][]))
                {
                    param = new ParamBoolMat(name, group, this, desc, stdValue, options);
                }
                else if (paramType == typeof(ParamIntMat) || paramType == typeof(int[][]))
                {
                    param = new ParamIntMat(name, group, this, desc, stdValue, options);
                }
                else if (paramType == typeof(ParamDoubleMat) || paramType == typeof(double[][]))
                {
                    param = new ParamDoubleMat(name, group, this, desc, stdValue, options);
                }
                else if (paramType == typeof(ParamString) || paramType == typeof(string) || paramType == typeof(String))
                {
                    param = new ParamString(name, group, this, desc, stdValue, options, buttons);
                }
                else if (paramType == typeof(ParamFileString))
                {
                    param = new ParamFileString(name, group, this, desc, stdValue, options);
                }
                else if (paramType == typeof(ParamStringMat) || paramType == typeof(string[][]) || paramType == typeof(String[][]))
                {
                    param = new ParamStringMat(name, group, this, desc, stdValue, options);
                }
                else if (paramType == typeof(ParamColor) || paramType == typeof(RGBColorFloat))
                {
                    param = new ParamColor(name, group, this, desc, stdValue, options);
                }
                else
                {
                    // message
                    logger.Error("Unknown parameter (generic) type '" + paramType.Name + "' for parameter name '" + name + "' in parameter set '" + paramSetName + "', not added.");

                    // return without adding parameter
                    return(null);
                }

                // check if the parameter is integer based
                if (param is ParamIntBase)
                {
                    // check if the minimum value is valid
                    if (!((ParamIntBase)param).setMinValue(minValue))
                    {
                        // message
                        logger.Error("Could not add parameter '" + name + "' in parameter set '" + paramSetName + "', minimum value '" + minValue + "' could not be parsed as an integer");

                        // return without adding parameter
                        return(null);
                    }

                    // check if the maximum value is valid
                    if (!((ParamIntBase)param).setMaxValue(maxValue))
                    {
                        // message
                        logger.Error("Could not add parameter '" + name + "' in parameter set '" + paramSetName + "', maximum value '" + maxValue + "' could not be parsed as an integer");

                        // return without adding parameter
                        return(null);
                    }
                }

                // check if the parameter is double based
                if (param is ParamDoubleBase)
                {
                    // check if the minimum value is valid
                    if (!((ParamDoubleBase)param).setMinValue(minValue))
                    {
                        // message
                        logger.Error("Could not add parameter '" + name + "' in parameter set '" + paramSetName + "', minimum value '" + minValue + "' could not be parsed as an integer");

                        // return without adding parameter
                        return(null);
                    }

                    // check if the maximum value is valid
                    if (!((ParamDoubleBase)param).setMaxValue(maxValue))
                    {
                        // message
                        logger.Error("Could not add parameter '" + name + "' in parameter set '" + paramSetName + "', maximum value '" + maxValue + "' could not be parsed as an integer");

                        // return without adding parameter
                        return(null);
                    }
                }

                // check if there is a standard value given
                if (!String.IsNullOrEmpty(stdValue))
                {
                    // set the standard value as initial value
                    if (!param.setValue(param.StdValue))
                    {
                        // message
                        logger.Error("Standard value for parameter '" + name + "' in parameter set '" + paramSetName + "' is invalid, parameter not added");

                        // return without adding parameter
                        return(null);
                    }
                }

                // add the parameter to the list
                paramList.Add(param);
                return(param);
            }
        }