Ejemplo n.º 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")
         {
         }
     }
 }
Ejemplo n.º 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));
                }
            }
        }
Ejemplo n.º 3
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));
        }