Beispiel #1
0
 //=====================================================================
 /// <summary>
 /// Store the forms controls into the list of TTypedValues.
 /// </summary>
 //=====================================================================
 private void StoreControls()
 {
     for (int i = 0; i < typedvals.Count; i++)
     {
         TTypedValue sdmlinit = typedvals[i];
         if (sdmlinit.Name == "rules")
         {
             sdmlinit.setElementCount((uint)richTextBox1.Lines.Length);
             for (uint line = 0; line < richTextBox1.Lines.Length; line++)
             {
                 sdmlinit.item(line + 1).setValue(richTextBox1.Lines[line]);
             }
         }
         if (sdmlinit.Name == "logfile")
         {
             if (checkBox1.Checked)
             {
                 sdmlinit.setValue(textBox1.Text);
             }
             else
             {
                 sdmlinit.setValue("");
             }
         }
         if (sdmlinit.Name == "log_set")
         {
         }
     }
 }
Beispiel #2
0
        //=========================================================================
        /// <summary>
        /// Writes the srcValue to destValue.
        /// </summary>
        /// <param name="srcValue">The source value.</param>
        /// <param name="destValue">The destination item.</param>
        //=========================================================================
        private void writeData(TTypedValue srcValue, TTypedValue destValue)
        {
            uint Idx;

            if (destValue.isScalar())
            {
                if (srcValue != null)
                {
                    destValue.setValue(srcValue);
                }
                else if ((destValue.baseType() >= TTypedValue.TBaseType.ITYPE_INT1) && (destValue.baseType() <= TTypedValue.TBaseType.ITYPE_DOUBLE))
                {
                    destValue.setValue(0);
                }
                else
                {
                    destValue.setValue("");
                }
            }
            else if (destValue.isArray())
            {
                if (srcValue == null)
                {
                    destValue.setElementCount(0);
                }
                else
                {
                    destValue.setElementCount(srcValue.count());
                    for (Idx = 1; Idx <= srcValue.count(); Idx++)
                    {
                        writeData(srcValue.item(Idx), destValue.item(Idx));
                    }
                }
            }
            else // record
            {
                for (Idx = 1; Idx <= destValue.count(); Idx++)
                {
                    writeData(srcValue.member(destValue.item(Idx).Name), destValue.item(Idx));
                }
            }
        }
Beispiel #3
0
        //============================================================================
        /// <summary>
        /// Gets the value of this XML element and stores it in the matching typed value.
        /// </summary>
        /// <param name="sAttrName">Name of the element.</param>
        /// <param name="aValue">The typed value to be set with the value found.</param>
        //============================================================================
        protected void parseRangeValue(String sAttrName, TTypedValue aValue)
        {
            XmlNode anode;
            String  sAttrValue;

            if (parser != null)
            {
                anode = parser.firstElementChild(parser.rootNode(), sAttrName);
                if (anode != null)
                {
                    sAttrValue = parser.getText(anode);
                    aValue.setValue(sAttrValue);
                }
            }
        }
        //=====================================================================
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public string updateValue(string value)
        {
            string tmp = value.Replace("\n", "");

            if (tmp.Equals(""))
            {
                value = DefaultValue;
            }

            //when this is a numeric value check it's range
            if ((_typedValue.isScalar()) && (!_typedValue.isTextType()) && (_typedValue.baseType() != TTypedValue.TBaseType.ITYPE_BOOL))
            {
                try
                {
                    double dValue = Convert.ToDouble(value);
                    if (TypedValue is TInitValue)
                    {
                        TInitValue initValue = TypedValue as TInitValue;

                        if (dValue > initValue.getMax().asDouble())
                        {
                            //value = initValue.getMax().asString();
                            value = DefaultValue;
                        }
                        if (dValue < initValue.getMin().asDouble())
                        {
                            //value = initValue.getMin().asString();
                            value = DefaultValue;
                        }
                    }
                }
                catch
                {
                    value = Value;
                }
            }
            _typedValue.setValue(value);

            return(value);
        }
Beispiel #5
0
        //=====================================================================
        /// <summary>
        /// Scan through the cultivar list in mvCotton.xml and find any that have
        /// parameters and form them into an XML document based on TSDMLValue.
        /// </summary>
        /// <returns>The cultivar list as XML.</returns>
        //=====================================================================
        private String WriteCultivars()
        {
            //create new TSDMLValue for the cultivar details
            TDDMLValue CultivarValues = new TDDMLValue(CULTIVARTYPE, "");

            CultivarValues.setElementCount(0);

            uint        cultivarCount = 0;
            XmlDocument ModelDoc      = new XmlDocument();
            String      ComponentType = Controller.ApsimData.Find(NodePath).Type;

            ModelDoc.LoadXml("<Model>" + Types.Instance.ModelContents(ComponentType) + "</Model>");
            foreach (XmlNode Child in ModelDoc.DocumentElement.ChildNodes)
            {
                if (XmlHelper.Attribute(Child, "cultivar").ToLower() == "yes")
                {
                    if (Child.ChildNodes.Count > 0)
                    {
                        XmlDocument CultivarDoc = new XmlDocument();
                        CultivarDoc.LoadXml(Child.OuterXml);
                        CultivarValues.setElementCount(++cultivarCount);
                        TTypedValue arrayitem = CultivarValues.item(cultivarCount);
                        arrayitem.member("cultivar").setValue(CultivarDoc.DocumentElement.Name); //read root tag name
                        foreach (XmlNode param in CultivarDoc.DocumentElement.ChildNodes)        //for each child of cultivardoc
                        {
                            if (param.NodeType == XmlNodeType.Element)
                            {
                                TTypedValue field = arrayitem.member(param.Name);
                                if (field != null)
                                {
                                    if (param.Name == "FRUDD" || param.Name == "BLTME" | param.Name == "WT")
                                    {
                                        //add array node values
                                        String arrayField = param.InnerText;
                                        if (arrayField.Contains(" "))
                                        {
                                            string[] VariableNameBits = arrayField.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                            double[] values           = MathUtility.StringsToDoubles(VariableNameBits);
                                            uint     count            = 0;
                                            foreach (double val in values)
                                            {
                                                field.setElementCount(++count);
                                                field.item(count).setValue(val);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        double val = Convert.ToDouble(param.InnerText); //these are all doubles
                                        field.setValue(val);                            //copy child to new doc
                                    }
                                }
                                else
                                {
                                    throw new Exception("Cannot set init value for " + param.Name + " in WriteCultivars()");
                                }
                            }
                        }
                    }
                }
            }
            TSDMLValue writer = new TSDMLValue("<type/>", "");

            return(writer.getText(CultivarValues, 0, 2));
        }