Пример #1
0
        /// <summary>
        /// Sets all the controls according to the given parameter
        /// </summary>
        /// <param name="iParameter"></param>
        internal void SetParameter(PlugInsInterfaces.DataTypes.IParameter iParameter)
        {
            iParameterRef = iParameter;

            //Parameters aliases is a dictionary indexed by IParameter.ID that can match to a value representing a new ID for this same parameter
            //For example, if the IParameter was created with the ID=123456789 and the user wants to see something nicer, the user can set a "Parameter Name"
            //in the main UI of GREET by right clicking on it. Then a new entry is added to the ParameterAliases <"123456789","New Name Set By User">
            Dictionary<string,string> data = ParametersExample.controler.CurrentProject.Data.ParametersAliases;

            //Unique ID for the parameter, this is set when a new parameter is created and cannot be changed in the database
            this.labelID.Text = iParameter.Id;

            //Tries to find a parameter name (or alias) for this IParameter object
            if (data != null && data.ContainsKey(iParameter.Id))
                this.labelAlias.Text = data[iParameter.Id];
            else
                this.labelAlias.Text = "No Alias for this parameter";

            //Retrieves the unit group name ("mass", "volume", "em_factor") that is used for this parameter
            //the unit group name is used to match with a SIUnit (unit used by the system which are only SI units)
            //and an DisplayUnit used to render the value when it is displayed in the GUI
            this.labelUnitGroup.Text = iParameter.UnitGroupName;

            Dictionary<string, IUnitGroup> groups = ParametersExample.controler.UnitGroupsAvailable;
            if(groups != null && groups.ContainsKey(iParameter.UnitGroupName)){
                IUnitGroup grp = groups[iParameter.UnitGroupName];

                //Sets the text of the label with the unit that is going to be used internally for calculating and storing this IParameter
                this.labelSiUnit2.Text = this.labelSIUnit.Text = grp.SIUnitStr;

                //Sets the text of the label with the unit that is going to be used for displaying this IParameter
                this.labelDisplayUnit.Text = grp.DisplayUnitStr;

                //Formatting the value using the default unit of the parameter and the user preferences defined in the option of the main GREET preferences windows
                this.labelGREETValue.Text = ParametersExample.controler.FormatValue(iParameter.GreetValue, grp.SIUnitStr, 0);
                //Here we are using the GREET Value which corresponds to the default value for that parameter provided by the GREET team
                //When the user changes the value of a parameter, it is only stored in the UserValue field. That way the user has the possiblity
                //to switch between GREETValue or UserValue for any parameter of the model

                //Removing events on the text box before setting the text and the event back
                this.textBox1.TextChanged -= new EventHandler(textBox1_TextChanged);
                this.textBox1.Text = iParameter.UserValue.ToString();
                this.textBox1.TextChanged += new EventHandler(textBox1_TextChanged);

                //Sets the text of the label as to show weather we are using the GREET original value for this parameter or the user entered value
                this.labelPreferGreet.Text = iParameter.UseOriginal.ToString();

                //Finds the value that the user wants to use for the calculations for this IParameter (GREETValue or UserValue) and displays it nicely formatted
                double preferedValue = (iParameter.UseOriginal) ? iParameter.GreetValue : iParameter.UserValue;
                this.labelFormatedPreferedValue.Text = ParametersExample.controler.FormatValue(preferedValue, grp.SIUnitStr, 0);
            }
            else{
                this.labelSiUnit2.Text = this.labelSIUnit.Text = "Unknown Group";
                this.labelUnitGroup.Text = "Unknown Group";
            }
        }
Пример #2
0
        /// <summary>
        /// Sets all the controls according to the given parameter
        /// </summary>
        /// <param name="iParameter"></param>
        internal void SetParameter(PlugInsInterfaces.DataTypes.IParameter iParameter)
        {
            iParameterRef = iParameter;

            //Parameters aliases is a dictionary indexed by IParameter.ID that can match to a value representing a new ID for this same parameter
            //For example, if the IParameter was created with the ID=123456789 and the user wants to see something nicer, the user can set a "Parameter Name"
            //in the main UI of GREET by right clicking on it. Then a new entry is added to the ParameterAliases <"123456789","New Name Set By User">
            Dictionary <string, string> data = ParametersExample.controler.CurrentProject.Data.ParametersAliases;

            //Unique ID for the parameter, this is set when a new parameter is created and cannot be changed in the database
            this.labelID.Text = iParameter.Id;

            //Tries to find a parameter name (or alias) for this IParameter object
            if (data != null && data.ContainsKey(iParameter.Id))
            {
                this.labelAlias.Text = data[iParameter.Id];
            }
            else
            {
                this.labelAlias.Text = "No Alias for this parameter";
            }

            //Retrieves the unit group name ("mass", "volume", "em_factor") that is used for this parameter
            //the unit group name is used to match with a SIUnit (unit used by the system which are only SI units)
            //and an DisplayUnit used to render the value when it is displayed in the GUI
            this.labelUnitGroup.Text = iParameter.UnitGroupName;

            Dictionary <string, IUnitGroup> groups = ParametersExample.controler.UnitGroupsAvailable;

            if (groups != null && groups.ContainsKey(iParameter.UnitGroupName))
            {
                IUnitGroup grp = groups[iParameter.UnitGroupName];

                //Sets the text of the label with the unit that is going to be used internally for calculating and storing this IParameter
                this.labelSiUnit2.Text = this.labelSIUnit.Text = grp.SIUnitStr;

                //Sets the text of the label with the unit that is going to be used for displaying this IParameter
                this.labelDisplayUnit.Text = grp.DisplayUnitStr;

                //Formatting the value using the default unit of the parameter and the user preferences defined in the option of the main GREET preferences windows
                this.labelGREETValue.Text = ParametersExample.controler.FormatValue(iParameter.GreetValue, grp.SIUnitStr, 0);
                //Here we are using the GREET Value which corresponds to the default value for that parameter provided by the GREET team
                //When the user changes the value of a parameter, it is only stored in the UserValue field. That way the user has the possiblity
                //to switch between GREETValue or UserValue for any parameter of the model

                //Removing events on the text box before setting the text and the event back
                this.textBox1.TextChanged -= new EventHandler(textBox1_TextChanged);
                this.textBox1.Text         = iParameter.UserValue.ToString();
                this.textBox1.TextChanged += new EventHandler(textBox1_TextChanged);

                //Sets the text of the label as to show weather we are using the GREET original value for this parameter or the user entered value
                this.labelPreferGreet.Text = iParameter.UseOriginal.ToString();

                //Finds the value that the user wants to use for the calculations for this IParameter (GREETValue or UserValue) and displays it nicely formatted
                double preferedValue = (iParameter.UseOriginal) ? iParameter.GreetValue : iParameter.UserValue;
                this.labelFormatedPreferedValue.Text = ParametersExample.controler.FormatValue(preferedValue, grp.SIUnitStr, 0);
            }
            else
            {
                this.labelSiUnit2.Text   = this.labelSIUnit.Text = "Unknown Group";
                this.labelUnitGroup.Text = "Unknown Group";
            }
        }