Example #1
0
        /// <summary>
        /// The PAW field in the view has changed.
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event arguments</param>
        private void OnPAWChanged(object sender, System.EventArgs e)
        {
            Commands.ChangeProperty command = new Commands.ChangeProperty(
                this.initialWater, "PAW", Convert.ToDouble(this.initialWaterView.PAW));

            this.explorerPresenter.CommandHistory.Add(command);
        }
Example #2
0
        /// <summary>
        /// Set the value of the graph models property
        /// </summary>
        /// <param name="name">The name of the property to set</param>
        /// <param name="value">The value of the property to set it to</param>
        private void SetModelProperty(string name, object value)
        {
            Series series = GetCurrentSeries();

            Commands.ChangeProperty command = new Commands.ChangeProperty(series, name, value);
            this.explorerPresenter.CommandHistory.Add(command);
        }
Example #3
0
        /// <summary>
        /// Set the value of the specified property
        /// </summary>
        /// <param name="property">The property to set the value of</param>
        /// <param name="value">The value to set the property to</param>
        private void SetPropertyValue(VariableProperty property, object value)
        {
            if (property.DataType.IsArray && value != null)
            {
                string[] stringValues = value.ToString().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (property.DataType == typeof(double[]))
                {
                    value = MathUtilities.StringsToDoubles(stringValues);
                }
                else if (property.DataType == typeof(int[]))
                {
                    value = MathUtilities.StringsToDoubles(stringValues);
                }
                else if (property.DataType == typeof(string[]))
                {
                    value = stringValues;
                }
                else
                {
                    throw new ApsimXException(this.model, "Invalid property type: " + property.DataType.ToString());
                }
            }
            else if (typeof(ICrop).IsAssignableFrom(property.DataType))
            {
                value = Apsim.Find(this.model, value.ToString()) as ICrop;
            }

            Commands.ChangeProperty cmd = new Commands.ChangeProperty(this.model, property.Name, value);
            this.explorerPresenter.CommandHistory.Add(cmd, true);
        }
Example #4
0
        /// <summary>
        /// User has added a series.
        /// </summary>
        /// <param name="sender">Event sender</param>
        /// <param name="e">Event arguments</param>
        private void OnSeriesAdded(object sender, EventArgs e)
        {
            Series seriesToAdd;

            int seriesIndex = Array.IndexOf(this.seriesView.SeriesNames, this.seriesView.SelectedSeriesName);

            if (seriesIndex != -1)
            {
                seriesToAdd = ReflectionUtilities.Clone(this.graph.Series[seriesIndex]) as Series;
            }
            else
            {
                seriesToAdd       = new Series();
                seriesToAdd.XAxis = Axis.AxisType.Bottom;
            }

            List <Series> allSeries = new List <Series>();

            allSeries.AddRange(graph.Series);
            allSeries.Add(seriesToAdd);
            seriesToAdd.Title = "Series" + allSeries.Count.ToString();
            Commands.ChangeProperty command = new Commands.ChangeProperty(this.graph, "Series", allSeries);
            this.explorerPresenter.CommandHistory.Add(command);
            this.PopulateSeriesNames();
            this.seriesView.SelectedSeriesName = seriesToAdd.Title;
        }
        /// <summary>
        /// The PAW field in the view has changed.
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event arguments</param>
        private void OnPAWChanged(object sender, System.EventArgs e)
        {
            Commands.ChangeProperty command = new Commands.ChangeProperty(
                this.initialWater, "PAW", Convert.ToDouble(this.initialWaterView.PAW, System.Globalization.CultureInfo.InvariantCulture));

            this.explorerPresenter.CommandHistory.Add(command);
        }
Example #6
0
        /// <summary>
        /// The relative to field in the view has changed.
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event arguments</param>
        private void OnRelativeToChanged(object sender, System.EventArgs e)
        {
            Commands.ChangeProperty command = new Commands.ChangeProperty(
                this.initialWater, "RelativeTo", this.initialWaterView.RelativeTo);

            this.explorerPresenter.CommandHistory.Add(command);
        }
Example #7
0
        /// <summary>
        /// Return a list of axis objects such that every series in AllSeries has an associated axis object.
        /// </summary>
        private void EnsureAllAxesExistInGraph()
        {
            // Get a list of all axis types that are referenced by the series.
            List <Models.Graph.Axis.AxisType> allAxisTypes = new List <Models.Graph.Axis.AxisType>();

            foreach (Series series in graph.Series)
            {
                allAxisTypes.Add(series.XAxis);
                allAxisTypes.Add(series.YAxis);
            }

            // Go through all graph axis objects. For each, check to see if it is still needed and
            // if so copy to our list.
            List <Axis> allAxes           = new List <Axis>();
            bool        unNeededAxisFound = false;

            foreach (Axis axis in this.graph.Axes)
            {
                if (allAxisTypes.Contains(axis.Type))
                {
                    allAxes.Add(axis);
                }
                else
                {
                    unNeededAxisFound = true;
                }
            }

            // Go through all series and make sure an axis object is present in our AllAxes list. If
            // not then go create an axis object.
            bool axisWasAdded = false;

            foreach (Series S in this.graph.Series)
            {
                if (!FindAxis(allAxes, S.XAxis))
                {
                    allAxes.Add(new Axis()
                    {
                        Type = S.XAxis
                    });
                    axisWasAdded = true;
                }
                if (!FindAxis(allAxes, S.YAxis))
                {
                    allAxes.Add(new Axis()
                    {
                        Type = S.YAxis
                    });
                    axisWasAdded = true;
                }
            }

            if (unNeededAxisFound || axisWasAdded)
            {
                Commands.ChangeProperty command = new Commands.ChangeProperty(graph, "Axes", allAxes);
                this.explorerPresenter.CommandHistory.Add(command);
            }
        }
Example #8
0
        /// <summary>The user has changed the commands</summary>
        /// <param name="sender">Event sender</param>
        /// <param name="e">Event arguments</param>
        private void OnCommandsChanged(object sender, EventArgs e)
        {
            this.explorerPresenter.CommandHistory.ModelChanged -= this.OnModelChanged;

            Commands.ChangeProperty command = new Commands.ChangeProperty(this.cultivar, "Commands", this.view.Lines);
            this.explorerPresenter.CommandHistory.Add(command);

            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
        }
Example #9
0
        /// <summary>
        /// The depth of wet soil field in the view has changed.
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event arguments</param>
        private void OnDepthWetSoilChanged(object sender, System.EventArgs e)
        {
            double depthOfWetSoil = Convert.ToDouble(this.initialWaterView.DepthOfWetSoil) * 10; // cm to mm

            Commands.ChangeProperty command = new Commands.ChangeProperty(
                this.initialWater, "DepthWetSoil", depthOfWetSoil);

            this.explorerPresenter.CommandHistory.Add(command);
        }
Example #10
0
        /// <summary>The user has changed the commands</summary>
        /// <param name="sender">Event sender</param>
        /// <param name="e">Event arguments</param>
        private void OnCommandsChanged(object sender, EventArgs e)
        {
            this.explorerPresenter.CommandHistory.ModelChanged -= this.OnModelChanged;

            Commands.ChangeProperty command = new Commands.ChangeProperty(this.cultivar, "Commands", this.view.Lines);
            this.explorerPresenter.CommandHistory.Add(command);

            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
        }
Example #11
0
        /// <summary>
        /// The percent full field in the view has changed.
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event arguments</param>
        private void OnPercentFullChanged(object sender, System.EventArgs e)
        {
            double fractionFull = (this.initialWaterView.PercentFull * 1.0) / 100;

            Commands.ChangeProperty command = new Commands.ChangeProperty(
                this.initialWater, "FractionFull", fractionFull);

            this.explorerPresenter.CommandHistory.Add(command);
        }
Example #12
0
        /// <summary>
        /// User has deleted a series.
        /// </summary>
        /// <param name="sender">Event sender</param>
        /// <param name="e">Event arguments</param>
        private void OnSeriesDeleted(object sender, EventArgs e)
        {
            int seriesIndex = Array.IndexOf(this.seriesView.SeriesNames, this.seriesView.SelectedSeriesName);

            if (seriesIndex != -1)
            {
                List <Series> allSeries = new List <Series>();
                allSeries.AddRange(graph.Series);
                allSeries.RemoveAt(seriesIndex);
                Commands.ChangeProperty command = new Commands.ChangeProperty(this.graph, "Series", allSeries);
                explorerPresenter.CommandHistory.Add(command);
                PopulateSeriesNames();
            }
        }
Example #13
0
 /// <summary>
 /// User has renamed a series.
 /// </summary>
 /// <param name="sender">Event sender</param>
 /// <param name="e">Event arguments</param>
 private void SeriesRenamed(object sender, EventArgs e)
 {
     string[] seriesNames = this.seriesView.SeriesNames;
     for (int i = 0; i < seriesNames.Length; i++)
     {
         if (this.graph.Series[i].Title != seriesNames[i])
         {
             this.explorerPresenter.CommandHistory.ModelChanged -= this.OnGraphModelChanged2;
             Commands.ChangeProperty command = new Commands.ChangeProperty(this.graph.Series[i], "Title", seriesNames[i]);
             explorerPresenter.CommandHistory.Add(command);
             this.explorerPresenter.CommandHistory.ModelChanged += this.OnGraphModelChanged2;
         }
     }
 }
Example #14
0
        /// <summary>
        /// The filled from top field in the view has changed.
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event arguments</param>
        private void OnFilledFromTopChanged(object sender, System.EventArgs e)
        {
            InitialWater.PercentMethodEnum percentMethod;
            if (this.initialWaterView.FilledFromTop)
            {
                percentMethod = InitialWater.PercentMethodEnum.FilledFromTop;
            }
            else
            {
                percentMethod = InitialWater.PercentMethodEnum.EvenlyDistributed;
            }

            Commands.ChangeProperty command = new Commands.ChangeProperty(
                this.initialWater, "PercentMethod", percentMethod);

            this.explorerPresenter.CommandHistory.Add(command);
        }
        /// <summary>
        /// The depth of wet soil field in the view has changed.
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event arguments</param>
        private void OnDepthWetSoilChanged(object sender, System.EventArgs e)
        {
            double depthOfWetSoil;

            if (this.initialWaterView.DepthOfWetSoil == int.MinValue)
            {
                depthOfWetSoil = Double.NaN;
            }
            else
            {
                depthOfWetSoil = Convert.ToDouble(this.initialWaterView.DepthOfWetSoil, System.Globalization.CultureInfo.InvariantCulture) * 10; // cm to mm
            }
            Commands.ChangeProperty command = new Commands.ChangeProperty(
                this.initialWater, "DepthWetSoil", depthOfWetSoil);

            this.explorerPresenter.CommandHistory.Add(command);
        }
Example #16
0
        /// <summary>The user has changed the commands</summary>
        /// <param name="sender">Event sender</param>
        /// <param name="e">Event arguments</param>
        private void OnCommandsChanged(object sender, EventArgs e)
        {
            try
            {
                if (this.view.Lines != this.cultivar.Command)
                {
                    this.explorerPresenter.CommandHistory.ModelChanged -= this.OnModelChanged;

                    Commands.ChangeProperty command = new Commands.ChangeProperty(this.cultivar, "Command", this.view.Lines);
                    this.explorerPresenter.CommandHistory.Add(command);

                    this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
                }
            }
            catch (Exception err)
            {
                explorerPresenter.MainPresenter.ShowError(err);
            }
        }
Example #17
0
        /// <summary>
        /// Set the value of the specified property
        /// </summary>
        /// <param name="property">The property to set the value of</param>
        /// <param name="value">The value to set the property to</param>
        private void SetPropertyValue(IVariable property, object value)
        {
            if (property.DataType.IsArray && value != null)
            {
                string[] stringValues = value.ToString().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (property.DataType == typeof(double[]))
                {
                    value = MathUtilities.StringsToDoubles(stringValues);
                }
                else if (property.DataType == typeof(int[]))
                {
                    value = MathUtilities.StringsToDoubles(stringValues);
                }
                else if (property.DataType == typeof(string[]))
                {
                    value = stringValues;
                }
                else
                {
                    throw new ApsimXException(model, "Invalid property type: " + property.DataType.ToString());
                }
            }
            else if (typeof(IPlant).IsAssignableFrom(property.DataType))
            {
                value = Apsim.Find(model, value.ToString()) as IPlant;
            }
            else if (property.DataType == typeof(DateTime))
            {
                value = Convert.ToDateTime(value);
            }
            else if (property.DataType.IsEnum)
            {
                value = VariableProperty.ParseEnum(property.DataType, value.ToString());
            }
            else if (property.Display != null &&
                     property.Display.Type == DisplayType.Model)
            {
                value = Apsim.Get(model, value.ToString());
            }

            Commands.ChangeProperty cmd = new Commands.ChangeProperty(model, property.Name, value);
            presenter.CommandHistory.Add(cmd, true);
        }
        /// <summary>
        /// The method used to specify initial water has changed
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event arguments</param>
        private void OnSpecifierChanged(object sender, System.EventArgs e)
        {
            double depthOfWetSoil;

            if (this.initialWaterView.DepthOfWetSoil == int.MinValue)
            {
                depthOfWetSoil = Double.NaN;
            }
            else
            {
                depthOfWetSoil = this.initialWater.TotalSoilDepth() * Math.Min(1.0, this.initialWater.FractionFull);
            }

            // The InitialWater model uses the value of DepthWetSoil as a flag
            // to inidicate whether specification is by depth or by fraction
            Commands.ChangeProperty command = new Commands.ChangeProperty(
                this.initialWater, "DepthWetSoil", depthOfWetSoil);

            this.explorerPresenter.CommandHistory.Add(command);
        }
        /// <summary>
        /// Set the value of the specified property
        /// </summary>
        /// <param name="property">The property to set the value of</param>
        /// <param name="value">The value to set the property to</param>
        private void SetPropertyValue(Model childmodel, VariableProperty property, object value)
        {
            if (property.DataType.IsArray && value != null)
            {
                string[] stringValues = value.ToString().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (property.DataType == typeof(double[]))
                {
                    value = MathUtilities.StringsToDoubles(stringValues);
                }
                else if (property.DataType == typeof(int[]))
                {
                    value = MathUtilities.StringsToDoubles(stringValues);
                }
                else if (property.DataType == typeof(string[]))
                {
                    value = stringValues;
                }
                else
                {
                    throw new ApsimXException(childmodel, "Invalid property type: " + property.DataType.ToString());
                }
            }
            else if (typeof(IPlant).IsAssignableFrom(property.DataType))
            {
                value = Apsim.Find(childmodel, value.ToString()) as IPlant;
            }
            else if (property.DataType == typeof(DateTime))
            {
                value = Convert.ToDateTime(value, CultureInfo.InvariantCulture);
            }
            else if (property.DataType.IsEnum)
            {
                value = Enum.Parse(property.DataType, value.ToString());
            }

            Commands.ChangeProperty cmd = new Commands.ChangeProperty(childmodel, property.Name, value);
            this.explorerPresenter.CommandHistory.Add(cmd, true);
        }
Example #20
0
        /// <summary>
        /// Save the state of the view back to the model class.
        /// </summary>
        private void SaveViewToModel()
        {
            // The ChangePropertyCommand below will trigger a call to OnModelChanged. We don't need to
            // repopulate the grid so stop the event temporarily until end of this method.
            this.explorerPresenter.CommandHistory.ModelChanged -= this.OnModelChanged;

            List <Test> tests = new List <Test>();

            for (int lineNumber = 0; lineNumber < this.view.Editor.Lines.Length; lineNumber++)
            {
                Test test = this.StringToTest(lineNumber);
                if (test != null)
                {
                    tests.Add(test);
                }
            }

            // Store 'tests' in model via a command.
            Commands.ChangeProperty command = new Commands.ChangeProperty(this.tests, "AllTests", tests.ToArray());
            this.explorerPresenter.CommandHistory.Add(command, true);

            // Reinstate the model changed event.
            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
        }
Example #21
0
        /// <summary>
        /// The percent full field in the view has changed.
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event arguments</param>
        private void OnPercentFullChanged(object sender, System.EventArgs e)
        {
            double fractionFull = (this.initialWaterView.PercentFull * 1.0) / 100;
            Commands.ChangeProperty command = new Commands.ChangeProperty(
                this.initialWater, "FractionFull", fractionFull);

            this.explorerPresenter.CommandHistory.Add(command);
        }
Example #22
0
 /// <summary>
 /// Set the value of the graph models property
 /// </summary>
 /// <param name="name">The name of the property to set</param>
 /// <param name="value">The value of the property to set it to</param>
 private void SetModelProperty(string name, object value)
 {
     Commands.ChangeProperty command = new Commands.ChangeProperty(series, name, value);
     this.explorerPresenter.CommandHistory.Add(command);
 }
        /// <summary>
        /// Save the grid back to the model.
        /// </summary>
        private void SaveGrid()
        {
            try
            {
                this.explorerPresenter.CommandHistory.ModelChanged -= this.OnModelChanged;

                // Get the data source of the profile grid.
                DataTable data = this.view.ProfileGrid.DataSource;

                // Maintain a list of all property changes that we need to make.
                List <Commands.ChangeProperty.Property> properties = new List <Commands.ChangeProperty.Property>();

                // Loop through all non-readonly properties, get an array of values from the data table
                // for the property and then set the property value.
                for (int i = 0; i < this.propertiesInGrid.Count; i++)
                {
                    // If this property is NOT readonly then set its value.
                    if (!this.propertiesInGrid[i].IsReadOnly)
                    {
                        // Get an array of values for this property.
                        Array values;
                        if (this.propertiesInGrid[i].DataType.GetElementType() == typeof(double))
                        {
                            values = DataTableUtilities.GetColumnAsDoubles(data, data.Columns[i].ColumnName);
                            if (!MathUtilities.ValuesInArray((double[])values))
                            {
                                values = null;
                            }
                            else
                            {
                                values = MathUtilities.RemoveMissingValuesFromBottom((double[])values);
                            }
                        }
                        else
                        {
                            values = DataTableUtilities.GetColumnAsStrings(data, data.Columns[i].ColumnName);
                            values = MathUtilities.RemoveMissingValuesFromBottom((string[])values);
                        }

                        // Is the value any different to the former property value?
                        bool changedValues;
                        if (this.propertiesInGrid[i].DataType == typeof(double[]))
                        {
                            changedValues = !MathUtilities.AreEqual((double[])values, (double[])this.propertiesInGrid[i].Value);
                        }
                        else
                        {
                            changedValues = !MathUtilities.AreEqual((string[])values, (string[])this.propertiesInGrid[i].Value);
                        }

                        if (changedValues)
                        {
                            // Store the property change.
                            Commands.ChangeProperty.Property property =
                                new Commands.ChangeProperty.Property(this.propertiesInGrid[i].Object, this.propertiesInGrid[i].Name, values);
                            properties.Add(property);
                        }
                    }
                }

                // If there are property changes pending, then commit the changes in a block.
                if (properties.Count > 0)
                {
                    Commands.ChangeProperty command = new Commands.ChangeProperty(properties);
                    this.explorerPresenter.CommandHistory.Add(command);
                }

                this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
            }
            catch (Exception e)
            {
                if (e is System.Reflection.TargetInvocationException)
                {
                    e = (e as System.Reflection.TargetInvocationException).InnerException;
                }

                this.explorerPresenter.MainPresenter.ShowError(e);
            }
        }
Example #24
0
        /// <summary>
        /// Save the grid back to the model.
        /// </summary>
        private void SaveGrid()
        {
            this.explorerPresenter.CommandHistory.ModelChanged -= this.OnModelChanged;

            // Get the data source of the profile grid.
            DataTable data = this.view.ProfileGrid.DataSource;

            // Maintain a list of all property changes that we need to make.
            List<Commands.ChangeProperty.Property> properties = new List<Commands.ChangeProperty.Property>();

            // Loop through all non-readonly properties, get an array of values from the data table
            // for the property and then set the property value.
            for (int i = 0; i < this.propertiesInGrid.Count; i++)
            {
                // If this property is NOT readonly then set its value.
                if (!this.propertiesInGrid[i].IsReadOnly)
                {
                    // Get an array of values for this property.
                    Array values;
                    if (this.propertiesInGrid[i].DataType.GetElementType() == typeof(double))
                    {
                        values = DataTableUtilities.GetColumnAsDoubles(data, data.Columns[i].ColumnName);
                        if (!MathUtilities.ValuesInArray((double[])values))
                            values = null;
                        else
                            values = MathUtilities.RemoveMissingValuesFromBottom((double[])values);
                    }
                    else
                    {
                        values = DataTableUtilities.GetColumnAsStrings(data, data.Columns[i].ColumnName);
                        values = MathUtilities.RemoveMissingValuesFromBottom((string[])values);
                    }

                    // Is the value any different to the former property value?
                    bool changedValues;
                    if (this.propertiesInGrid[i].DataType == typeof(double[]))
                    {
                        changedValues = !MathUtilities.AreEqual((double[])values, (double[])this.propertiesInGrid[i].Value);
                    }
                    else
                    {
                        changedValues = !MathUtilities.AreEqual((string[])values, (string[])this.propertiesInGrid[i].Value);
                    }

                    if (changedValues)
                    {
                        // Store the property change.
                        Commands.ChangeProperty.Property property = new Commands.ChangeProperty.Property();
                        property.Name = this.propertiesInGrid[i].Name;
                        property.Obj = this.propertiesInGrid[i].Object;
                        property.NewValue = values;
                        properties.Add(property);
                    }
                }
            }

            // If there are property changes pending, then commit the changes in a block.
            if (properties.Count > 0)
            {
                Commands.ChangeProperty command = new Commands.ChangeProperty(properties);
                this.explorerPresenter.CommandHistory.Add(command);
            }

            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
        }
Example #25
0
 /// <summary>
 /// User has cleared all series.
 /// </summary>
 /// <param name="sender">Event sender</param>
 /// <param name="e">Event arguments</param>
 private void OnSeriesCleared(object sender, EventArgs e)
 {
     Commands.ChangeProperty command = new Commands.ChangeProperty(this.graph, "Series", new List <Series>());
     explorerPresenter.CommandHistory.Add(command);
     PopulateSeriesNames();
 }
Example #26
0
 /// <summary>
 /// The auto export option has been changed.
 /// </summary>
 /// <param name="sender">Sender of the event</param>
 /// <param name="e">Event arguments</param>
 private void OnAutoExportClicked(object sender, EventArgs e)
 {
     Commands.ChangeProperty command = new Commands.ChangeProperty(this.dataStore, "AutoExport", this.dataStoreView.AutoExport);
     this.explorerPresenter.CommandHistory.Add(command);
 }
Example #27
0
 /// <summary>
 /// Set the value of the specified property
 /// </summary>
 /// <param name="property">The property to set the value of</param>
 /// <param name="value">The value to set the property to</param>
 private void SetPropertyValue(Model childmodel, VariableProperty property, object value)
 {
     Commands.ChangeProperty cmd = new Commands.ChangeProperty(childmodel, property.Name, value);
     this.explorerPresenter.CommandHistory.Add(cmd, true);
 }
Example #28
0
 /// <summary>
 /// Overall regression checkbox has been changed by the user.
 /// </summary>
 /// <param name="sender">Event sender</param>
 /// <param name="e">Event arguments</param>
 private void OnOverallRegressionChanged(object sender, EventArgs e)
 {
     Commands.ChangeProperty command = new Commands.ChangeProperty(this.graph, "ShowRegressionLine", this.seriesView.SeriesEditor.OverallRegression);
     this.explorerPresenter.CommandHistory.Add(command);
 }
Example #29
0
 /// <summary>
 /// The auto export option has been changed.
 /// </summary>
 /// <param name="sender">Sender of the event</param>
 /// <param name="e">Event arguments</param>
 private void OnAutoExportClicked(object sender, EventArgs e)
 {
     Commands.ChangeProperty command = new Commands.ChangeProperty(this.dataStore, "AutoExport", this.dataStoreView.AutoExport);
     this.explorerPresenter.CommandHistory.Add(command);
 }
Example #30
0
        /// <summary>
        /// Save the state of the view back to the model class.
        /// </summary>
        private void SaveViewToModel()
        {
            // The ChangePropertyCommand below will trigger a call to OnModelChanged. We don't need to
            // repopulate the grid so stop the event temporarily until end of this method.
            this.explorerPresenter.CommandHistory.ModelChanged -= this.OnModelChanged;

            List<Test> tests = new List<Test>();
            for (int lineNumber = 0; lineNumber < this.view.Editor.Lines.Length; lineNumber++)
            {
                Test test = this.StringToTest(lineNumber);
                if (test != null)
                {
                    tests.Add(test);
                }
            }

            // Store 'tests' in model via a command.
            Commands.ChangeProperty command = new Commands.ChangeProperty(this.tests, "AllTests", tests.ToArray());
            this.explorerPresenter.CommandHistory.Add(command, true);

            // Reinstate the model changed event.
            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
        }
Example #31
0
        /// <summary>
        /// Save the grid back to the model.
        /// </summary>
        private void SaveGrid()
        {
            this.explorerPresenter.CommandHistory.ModelChanged -= this.OnModelChanged;

            // Get the data source of the profile grid.
            DataTable data = this.xyPairsView.VariablesGrid.DataSource;

            // Maintain a list of all property changes that we need to make.
            List<Commands.ChangeProperty.Property> properties = new List<Commands.ChangeProperty.Property>();

            //add missing data as 0 otherwise it will throw an exception
            //could make this work as an entire row, but will stick to X & Y columns for now
            /*
            for (int Row = 0; Row != data.Rows.Count; Row++)
            {
                if (data.Rows[Row]["Y"].ToString() == "" && data.Rows[Row]["X"].ToString() != "")
                    data.Rows[Row]["Y"] = "0";
                if (data.Rows[Row]["X"].ToString() == "" && data.Rows[Row]["Y"].ToString() != "")
                    data.Rows[Row]["X"] = "0";
                if (data.Rows[Row]["Y"].ToString() == "" && data.Rows[Row]["X"].ToString() == "")
                    break;
            }
            */
            // Loop through all non-readonly properties, get an array of values from the data table
            // for the property and then set the property value.
            for (int i = 0; i < this.propertiesInGrid.Count; i++)
            {
                // If this property is NOT readonly then set its value.
                if (!this.propertiesInGrid[i].IsReadOnly)
                {
                    // Get an array of values for this property.
                    Array values;
                    if (this.propertiesInGrid[i].DataType.GetElementType() == typeof(double))
                    {
                        values = DataTableUtilities.GetColumnAsDoubles(data, data.Columns[i].ColumnName);
                        if (!MathUtilities.ValuesInArray((double[])values))
                            values = null;
                        else
                            values = MathUtilities.RemoveMissingValuesFromBottom((double[])values);
                    }
                    else
                    {
                        values = DataTableUtilities.GetColumnAsStrings(data, data.Columns[i].ColumnName);
                        values = MathUtilities.RemoveMissingValuesFromBottom((string[])values);
                    }

                    // Is the value any different to the former property value?
                    bool changedValues;
                    if (this.propertiesInGrid[i].DataType == typeof(double[]))
                    {
                        changedValues = !MathUtilities.AreEqual((double[])values, (double[])this.propertiesInGrid[i].Value);
                    }
                    else
                    {
                        changedValues = !MathUtilities.AreEqual((string[])values, (string[])this.propertiesInGrid[i].Value);
                    }

                    if (changedValues)
                    {
                        // Store the property change.
                        Commands.ChangeProperty.Property property = new Commands.ChangeProperty.Property();
                        property.Name = this.propertiesInGrid[i].Name;
                        property.Obj = this.propertiesInGrid[i].Object;
                        property.NewValue = values;
                        properties.Add(property);
                    }
                }
            }

            // If there are property changes pending, then commit the changes in a block.
            if (properties.Count > 0)
            {
                Commands.ChangeProperty command = new Commands.ChangeProperty(properties);
                this.explorerPresenter.CommandHistory.Add(command);
            }

            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
        }
Example #32
0
        /// <summary>
        /// The depth of wet soil field in the view has changed.
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event arguments</param>
        private void OnDepthWetSoilChanged(object sender, System.EventArgs e)
        {
            double depthOfWetSoil = Convert.ToDouble(this.initialWaterView.DepthOfWetSoil) * 10; // cm to mm
            Commands.ChangeProperty command = new Commands.ChangeProperty(
                this.initialWater, "DepthWetSoil", depthOfWetSoil);

            this.explorerPresenter.CommandHistory.Add(command);
        }
Example #33
0
        /// <summary>
        /// The filled from top field in the view has changed.
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event arguments</param>
        private void OnFilledFromTopChanged(object sender, System.EventArgs e)
        {
            InitialWater.PercentMethodEnum percentMethod;
            if (this.initialWaterView.FilledFromTop)
            {
                percentMethod = InitialWater.PercentMethodEnum.FilledFromTop;
            }
            else
            {
                percentMethod = InitialWater.PercentMethodEnum.EvenlyDistributed;
            }

            Commands.ChangeProperty command = new Commands.ChangeProperty(
                this.initialWater, "PercentMethod", percentMethod);

            this.explorerPresenter.CommandHistory.Add(command);
        }
Example #34
0
        /// <summary>
        /// The PAW field in the view has changed.
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event arguments</param>
        private void OnPAWChanged(object sender, System.EventArgs e)
        {
            Commands.ChangeProperty command = new Commands.ChangeProperty(
                this.initialWater, "PAW", Convert.ToDouble(this.initialWaterView.PAW));

            this.explorerPresenter.CommandHistory.Add(command);
        }
Example #35
0
        /// <summary>
        /// Set the value of the specified property
        /// </summary>
        /// <param name="property">The property to set the value of</param>
        /// <param name="value">The value to set the property to</param>
        private void SetPropertyValue(VariableProperty property, object value)
        {
            if (property.DataType.IsArray && value != null)
            {
                string[] stringValues = value.ToString().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (property.DataType == typeof(double[]))
                {
                    value = MathUtilities.StringsToDoubles(stringValues);
                }
                else if (property.DataType == typeof(int[]))
                {
                    value = MathUtilities.StringsToDoubles(stringValues);
                }
                else if (property.DataType == typeof(string[]))
                {
                    value = stringValues;
                }
                else
                {
                    throw new ApsimXException(this.model, "Invalid property type: " + property.DataType.ToString());
                }
            }
            else if (typeof(ICrop).IsAssignableFrom(property.DataType))
            {
                value = Apsim.Find(this.model, value.ToString()) as ICrop;
            }
            else if (property.DataType.IsEnum)
            {
                value = Enum.Parse(property.DataType, value.ToString());
            }

            Commands.ChangeProperty cmd = new Commands.ChangeProperty(this.model, property.Name, value);
            this.explorerPresenter.CommandHistory.Add(cmd, true);
        }
Example #36
0
        /// <summary>
        /// Save the grid back to the model.
        /// </summary>
        private void SaveGrid()
        {
            this.presenter.CommandHistory.ModelChanged -= this.OnModelChanged;

            // Get the data source of the profile grid.
            DataTable data = this.xYPairsView.VariablesGrid.DataSource;

            // Maintain a list of all property changes that we need to make.
            List <Commands.ChangeProperty.Property> properties = new List <Commands.ChangeProperty.Property>();

            // add missing data as 0 otherwise it will throw an exception
            // could make this work as an entire row, but will stick to X & Y columns for now

            /*
             * for (int Row = 0; Row != data.Rows.Count; Row++)
             * {
             *  if (data.Rows[Row]["Y"].ToString() == "" && data.Rows[Row]["X"].ToString() != "")
             *      data.Rows[Row]["Y"] = "0";
             *  if (data.Rows[Row]["X"].ToString() == "" && data.Rows[Row]["Y"].ToString() != "")
             *      data.Rows[Row]["X"] = "0";
             *  if (data.Rows[Row]["Y"].ToString() == "" && data.Rows[Row]["X"].ToString() == "")
             *      break;
             * }
             */
            //// Loop through all non-readonly properties, get an array of values from the data table
            //// for the property and then set the property value.
            for (int i = 0; i < this.propertiesInGrid.Count; i++)
            {
                // If this property is NOT readonly then set its value.
                if (!this.propertiesInGrid[i].IsReadOnly)
                {
                    // Get an array of values for this property.
                    Array values;
                    if (this.propertiesInGrid[i].DataType.GetElementType() == typeof(double))
                    {
                        values = DataTableUtilities.GetColumnAsDoubles(data, data.Columns[i].ColumnName);
                        if (!MathUtilities.ValuesInArray((double[])values))
                        {
                            values = null;
                        }
                        else
                        {
                            values = MathUtilities.RemoveMissingValuesFromBottom((double[])values);
                        }
                    }
                    else
                    {
                        values = DataTableUtilities.GetColumnAsStrings(data, data.Columns[i].ColumnName);
                        values = MathUtilities.RemoveMissingValuesFromBottom((string[])values);
                    }

                    // Is the value any different to the former property value?
                    bool changedValues;
                    if (this.propertiesInGrid[i].DataType == typeof(double[]))
                    {
                        changedValues = !MathUtilities.AreEqual((double[])values, (double[])this.propertiesInGrid[i].Value);
                    }
                    else
                    {
                        changedValues = !MathUtilities.AreEqual((string[])values, (string[])this.propertiesInGrid[i].Value);
                    }

                    if (changedValues)
                    {
                        // Store the property change.
                        Commands.ChangeProperty.Property property =
                            new Commands.ChangeProperty.Property(this.propertiesInGrid[i].Object, this.propertiesInGrid[i].Name, values);
                        properties.Add(property);
                    }
                }
            }

            // If there are property changes pending, then commit the changes in a block.
            if (properties.Count > 0)
            {
                Commands.ChangeProperty command = new Commands.ChangeProperty(properties);
                this.presenter.CommandHistory.Add(command);
            }

            this.presenter.CommandHistory.ModelChanged += this.OnModelChanged;
        }
Example #37
0
        /// <summary>
        /// The relative to field in the view has changed.
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event arguments</param>
        private void OnRelativeToChanged(object sender, System.EventArgs e)
        {
            Commands.ChangeProperty command = new Commands.ChangeProperty(
                this.initialWater, "RelativeTo", this.initialWaterView.RelativeTo);

            this.explorerPresenter.CommandHistory.Add(command);
        }