Ejemplo n.º 1
0
        /// <summary>Perform the command</summary>
        /// <param name="commandHistory">The command history.</param>
        public void Do(CommandHistory commandHistory)
        {
            try
            {
                parent = Apsim.Get(presenter.ApsimXFile, parentPath) as IModel;
                if (parent == null)
                {
                    throw new Exception("Cannot find model " + parentPath);
                }

                IModel newModel = FileFormat.ReadFromString <IModel>(childString, out List <Exception> exceptions);
                if (exceptions != null && exceptions.Count > 0)
                {
                    presenter.MainPresenter.ShowError(exceptions);
                    return;
                }
                modelToAdd = newModel;

                if (modelToAdd is Simulations && modelToAdd.Children.Count == 1)
                {
                    modelToAdd = modelToAdd.Children[0];
                }

                Structure.Add(modelToAdd, parent);
                var nodeDescription = presenter.GetNodeDescription(modelToAdd);
                view.Tree.AddChild(Apsim.FullPath(parent), nodeDescription);
                modelAdded = true;
            }
            catch (Exception err)
            {
                presenter.MainPresenter.ShowError(err);
                modelAdded = false;
            }
        }
Ejemplo n.º 2
0
        /// <summary>Perform the command</summary>
        /// <param name="commandHistory">The command history.</param>
        public void Do(CommandHistory commandHistory)
        {
            try
            {
                parent = Apsim.Get(presenter.ApsimXFile, parentPath) as IModel;
                if (parent == null)
                {
                    throw new Exception("Cannot find model " + parentPath);
                }

                modelToAdd = child;

                if (modelToAdd is Simulations && modelToAdd.Children.Count == 1)
                {
                    modelToAdd = modelToAdd.Children[0];
                }

                Structure.Add(modelToAdd, parent);
                var nodeDescription = presenter.GetNodeDescription(modelToAdd);
                view.Tree.AddChild(Apsim.FullPath(parent), nodeDescription);
                modelAdded = true;
            }
            catch (Exception err)
            {
                presenter.MainPresenter.ShowError(err);
                modelAdded = false;
            }
        }
Ejemplo n.º 3
0
        /// <summary>Perform the command</summary>
        /// <param name="CommandHistory">The command history.</param>
        public void Do(CommandHistory CommandHistory)
        {
            IModel parent     = modelToReplace.Parent as IModel;
            int    modelIndex = parent.Children.IndexOf(modelToReplace as Model);

            // Replace model.
            try
            {
                this.explorerView.Tree.Delete(Apsim.FullPath(this.modelToReplace));
                parent.Children.Remove(modelToReplace as Model);
                parent.Children.Insert(modelIndex, modelToInsert as Model);
                modelToInsert.Parent = parent;
                var nodeDescription = presenter.GetNodeDescription(modelToInsert);
                this.explorerView.Tree.AddChild(Apsim.FullPath(parent), nodeDescription, modelIndex);
                modelWasReplaced = true;
            }
            catch (Exception err)
            {
                presenter.MainPresenter.ShowError(err);
                modelWasReplaced = false;
            }
        }