/// <summary>
        /// use string array to initialize, better use enum.
        /// </summary>
        public CapeOptionParameter(string name, IEnumerable <string> optionList,
                                   CapeParamMode mode, string defOption = null, bool restrictedToList = true)
            : base(name, CapeParamType.CAPE_OPTION, mode, UnitCategoryEnum.Dimensionless)
        {
            this._enumType = null;
            if (optionList != null)
            {
                _optionList = new List <string>(optionList);
            }
            else
            {
                _optionList = new List <string>();
            }
            RestrictedToList = restrictedToList;

            if (_optionList.Count() == 0)
            {
                DefaultValue = null;
            }
            else if (defOption == null)
            {
                DefaultValue = _optionList.FirstOrDefault();
            }
            else
            {
                DefaultValue = defOption;
            }

            StringValue = DefaultValue;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructor for the boolean-valued parameter
 /// </summary>
 /// <remarks>
 /// This constructor sets the <see cref = "ICapeIdentification.ComponentName"/> of the
 /// parameter. The parameter's value and default value are set to the value.
 /// Additionally, the parameters <see cref = "CapeOpen.CapeParamMode"/> is set.
 /// </remarks>
 /// <param name = "name">Sets as the ComponentName of the parameter's ICapeIdentification interface.</param>
 /// <param name = "value">Sets the inital and default value of the parameter.</param>
 /// <param name = "mode">Sets the CapeParamMode mode of the parameter.</param>
 public BooleanParameter(String name, bool value, CapeParamMode mode)
     : base(name, String.Empty, mode)
 {
     m_value        = value;
     m_DefaultValue = value;
     this.Mode      = mode;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// constructor of array parameter
 /// </summary>
 public CapeArrayParameter(string name, CapeParamMode mode)
     : base(name, CapeParamType.CAPE_ARRAY, mode, UnitCategoryEnum.Dimensionless)
 {
     _array     = new List <ICapeParameter>();
     ValStatus  = CapeValidationStatus.CAPE_NOT_VALIDATED;
     IsReadOnly = false;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Populates a SerializationInfo with the data needed to serialize the <see craf = "UnitOperationWrapper"/>.
        /// </summary>
        /// <remarks>This method restores serializable .NET-based port connections. COM-bassed stream objects may need to
        /// be connected manually to the ports.</remarks>
        /// <param name="info">The SerializationInfo to populate the <see craf = "UnitOperationWrapper"/> with data.</param>
        /// <param name="context">The destination <see craf = "StreamingContext"/> for this serialization.</param>
        void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
        {
            bool isCOM = p_Unit.GetType().IsCOMObject;

            info.AddValue("isCOM", isCOM, typeof(bool));
            if (isCOM)
            {
                info.AddValue("CLSID", m_CLSID.ToString(), typeof(string));
            }
            else
            {
                info.AddValue("Unit Type", p_Unit.GetType(), typeof(Type));
                info.AddValue("Unit Assembly", p_Unit.GetType().Assembly, typeof(System.Reflection.Assembly));
            }

            ICapeIdentification p_Id = (ICapeIdentification)p_Unit;

            info.AddValue("Unit Name", p_Id.ComponentName, typeof(string));
            info.AddValue("Unit Description", p_Id.ComponentDescription, typeof(string));
            // ICapeUtilities p_Util = (ICapeUtilities)p_Unit;
            //if (this.SimulationContext != null)
            //{
            //    if (this.SimulationContext.GetType().IsSerializable)
            //    {
            //        info.AddValue("Simulation Context", this.SimulationContext, typeof(object));
            //    }
            //    else
            //    {
            //        info.AddValue("Simulation Context", null, typeof(object));
            //    }
            //}
            // else info.AddValue("Simulation Context", null, typeof(object));
            object[]        paramValues = new object[this.Parameters.Count];
            CapeParamMode[] paramModes  = new CapeParamMode[this.Parameters.Count];
            int             i           = 0;

            foreach (ICapeParameter parameter in this.Parameters)
            {
                paramValues[i] = parameter.value;
                paramModes[i]  = parameter.Mode;
                i++;
            }
            info.AddValue("Parameter Values", paramValues, typeof(object[]));
            info.AddValue("Parameter Modes", paramModes, typeof(CapeParamMode[]));
            object[] portConnections = new object[this.Ports.Count];
            i = 0;
            foreach (ICapeUnitPort port in this.Ports)
            {
                portConnections[i] = port.connectedObject;
                if (portConnections[i] != null)
                {
                    if (!portConnections[i].GetType().IsSerializable)
                    {
                        portConnections[i] = null;
                    }
                }
                i++;
            }
            info.AddValue("PortConnections", portConnections, typeof(object[]));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a new instance of the integer-valued parameter class.
 /// </summary>
 /// <remarks>
 /// <para>The default value is set to the inital value of the parameter. The upper
 /// bound is set to Int32.MaxValue (2,147,483,647) and the lower bound is set to
 /// Int32.MinValue (-2,147,483,648). The mode is set to CapeParamMode.CAPE_INPUT_OUTPUT.</para>
 /// </remarks>
 /// <param name = "name">Sets as the ComponentName of the parameter's ICapeIdentification interface.</param>
 /// <param name = "value">Sets the inital value of the parameter.</param>
 /// <param name = "mode">Sets the CapeParamMode mode of the parameter</param>
 public IntegerParameter(String name, int value, CapeParamMode mode)
     : base(name, String.Empty, mode)
 {
     m_value        = value;
     this.Mode      = mode;
     m_LowerBound   = int.MinValue;
     m_UpperBound   = int.MaxValue;
     m_DefaultValue = value;
 }
Ejemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 protected CapeParameterBase(string name, CapeParamType type, CapeParamMode mode, UnitCategoryEnum unitCategory)
     : base(name, "", false)
 {
     ValStatus = CapeValidationStatus.CAPE_NOT_VALIDATED;
     //value = null;
     Mode           = mode;
     Type           = type;
     Dimensionality = Units.GetDimensionality(unitCategory);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// constructor of int parameter
 /// </summary>
 public CapeIntParameter(string name,
                         CapeParamMode mode, int minVal = int.MinValue,
                         int maxVal = int.MaxValue, int defaultVal = default(int))
     : base(name, CapeParamType.CAPE_INT, mode, UnitCategoryEnum.Dimensionless)
 {
     LowerBound   = minVal;
     UpperBound   = maxVal;
     DefaultValue = defaultVal;
     IntValue     = DefaultValue;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// real parameter
 /// </summary>
 /// <paramCollection name="unitCategory">unit type</paramCollection>
 /// <paramCollection name="mode">if set to Input, the value won't change with unit in default window</paramCollection>
 public CapeRealParameter(string name, UnitCategoryEnum unitCategory,
                          CapeParamMode mode, double minVal = double.MinValue,
                          double maxVal = double.MaxValue, double defaultVal = double.NaN)
     : base(name, CapeParamType.CAPE_REAL, mode, unitCategory)
 {
     this.LowerBound     = minVal;
     this.UpperBound     = maxVal;
     this.DefaultValue   = defaultVal;
     DoubleValue         = DefaultValue;
     CurrentUnitCategory = unitCategory;
     CurrentUnit         = Units.GetSIUnit(unitCategory);
 }
Ejemplo n.º 9
0
        public static CapeOpenParameterMode Map(CapeParamMode mode)
        {
            switch (mode)
            {
            case CapeParamMode.CAPE_INPUT:
                return(CapeOpenParameterMode.Read);

            case CapeParamMode.CAPE_OUTPUT:
                return(CapeOpenParameterMode.Write);

            case CapeParamMode.CAPE_INPUT_OUTPUT:
                return(CapeOpenParameterMode.ReadWrite);

            default:
                throw new CapeOpenException();
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Highly Recommended! Use a enum type to initialize this parameter
        /// </summary>
        public CapeOptionParameter(string name, Type enumType, CapeParamMode mode,
                                   Enum defOption = null, bool restrictedToList = true)
            : base(name, CapeParamType.CAPE_OPTION, mode, UnitCategoryEnum.Dimensionless)
        {
            this._enumType   = enumType;
            _optionList      = new List <string>(enumType.GetEnumNames());
            RestrictedToList = restrictedToList;

            if (_optionList.Count() == 0)
            {
                DefaultValue = null;
            }
            else if (defOption == null)
            {
                DefaultValue = _optionList.FirstOrDefault();
            }
            else
            {
                DefaultValue = enumType.GetEnumName(defOption);
            }

            StringValue = DefaultValue;
        }
Ejemplo n.º 11
0
 /// <summary>
 /// constructor of bool parameter
 /// </summary>
 public CapeBooleanParameter(string name, CapeParamMode mode, bool defVal = false)
     : base(name, CapeParamType.CAPE_BOOLEAN, mode, UnitCategoryEnum.Dimensionless)
 {
     DefaultValue = defVal;
     BoolValue    = DefaultValue;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Constructor for the boolean-valued parameter
 /// </summary>
 /// <remarks>
 /// This constructor sets the <see cref = "ICapeIdentification.ComponentName"/> and
 /// <see cref = "ICapeIdentification.ComponentDescription"/> of the
 /// parameter. The parameter's value and default value are set to the value.
 /// Additionally, the parameters CapeParamMode is set.
 /// </remarks>
 /// <param name = "name">Sets as the ComponentName of the parameter's ICapeIdentification interface.</param>
 /// <param name = "description">Sets as the ComponentDescription of the parameter's ICapeIdentification interface.</param>
 /// <param name = "value">Sets the inital value of the parameter.</param>
 /// <param name = "defaultValue">Sets the default value of the parameter.</param>
 /// <param name = "mode">Sets the CapeParamMode mode of the parameter.</param>
 public BooleanParameter(String name, String description, bool value, bool defaultValue, CapeParamMode mode)
     : base(name, description, mode)
 {
     m_value        = value;
     this.Mode      = mode;
     m_DefaultValue = defaultValue;
     m_ValStatus    = CapeOpen.CapeValidationStatus.CAPE_VALID;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Constructor for the boolean-valued parameter
 /// </summary>
 /// <remarks>
 /// This constructor sets the ICapeIdentification.ComponentName and
 /// ICapeIdentification.ComponentDescription of the
 /// parameter. The parameter's value and default value are set to the value.
 /// Additionally, the parameters CapeParameterMode is set.
 /// </remarks>
 /// <param name = "name">Sets as the ComponentName of the parameter's ICapeIdentification interface.</param>
 /// <param name = "description">Sets as the ComponentDescription of the parameter's ICapeIdentification interface.</param>
 /// <param name = "value">Sets the inital value of the parameter.</param>
 /// <param name = "defaultValue">Sets the default value of the parameter.</param>
 /// <param name = "options">String array used as the list acceptable options.</param>
 /// <param name = "restricted">Sets whether the parameter value is restricted to values in the option list.</param>
 /// <param name = "mode">Sets the CapeParamMode mode of the parameter.</param>
 public OptionParameter(String name, String description, String value, String defaultValue, String[] options, bool restricted, CapeParamMode mode)
     : base(name, description, mode)
 {
     m_value        = value;
     this.Mode      = mode;
     m_DefaultValue = defaultValue;
     m_OptionList   = options;
     m_Restricted   = restricted;
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates a new instance of the integer-valued parameter class using the values enterred.
        /// </summary>
        /// <remarks>
        /// The default value, upper and lower
        /// bound, as well as the mode of the parameter are specified in this constructor.
        /// </remarks>
        /// <param name = "name">Sets as the ComponentName of the parameter's ICapeIdentification interface.</param>
        /// <param name = "description">Sets as the ComponentDescription of the parameter's ICapeIdentification interface.</param>
        /// <param name = "value">Sets the inital value of the parameter.</param>
        /// <param name = "defaultValue">Sets the default value of the parameter.</param>
        /// <param name = "minValue">Sets the lower bound of the parameter.</param>
        /// <param name = "maxValue">Sets the upper bound of the parameter.</param>
        /// <param name = "mode">Sets the CapeParamMode mode of the parameter.</param>
        public IntegerParameter(String name, String description, int value, int defaultValue, int minValue, int maxValue, CapeParamMode mode)
            : base(name, description, mode)
        {
            m_value        = value;
            this.Mode      = mode;
            m_LowerBound   = minValue;
            m_UpperBound   = maxValue;
            m_DefaultValue = defaultValue;
            String message = "";

            if (!this.Validate(ref message))
            {
                System.Windows.Forms.MessageBox.Show(message, String.Concat("Invalid Parameter Value: ", this.ComponentName));
            }
        }
Ejemplo n.º 15
0
 /// <summary>
 ///
 /// </summary>
 /// <paramCollection name="name"></paramCollection>
 /// <paramCollection name="mode"></paramCollection>
 public CapeMatrixParameter(string name, CapeParamMode mode)
     : base(name, CapeParamType.CAPE_ARRAY, mode, UnitCategoryEnum.Dimensionless)
 {
     _matrix = new List <List <ICapeParameter> >();
 }