Beispiel #1
0
 /// <summary>Perform the command</summary>
 /// <param name="commandHistory">The command history instance</param>
 public void Do(CommandHistory commandHistory)
 {
     this.explorerView.Delete(Apsim.FullPath(this.modelToDelete));
     pos             = this.parent.Children.IndexOf(this.modelToDelete as Model);
     modelWasRemoved = Apsim.Delete(this.modelToDelete as Model);
 }
Beispiel #2
0
        /// <summary>
        /// Convert the simulation decription to a simulation.
        /// path.
        /// </summary>
        public Simulation ToSimulation()
        {
            try
            {
                AddReplacements();

                Simulation newSimulation;
                if (doClone)
                {
                    newSimulation = Apsim.Clone(baseSimulation) as Simulation;

                    // If there is a child DataStore
                    // remove it and use the same one as in baseSimulation. This is
                    // because we want to use the same DataStore for all simulations
                    // and not have a separate DataStore instance for each simulation.
                    Model goodStorage;
                    if (topLevelModel == null)
                    {
                        goodStorage = Apsim.Child(newSimulation, typeof(IDataStore)) as Model;
                    }
                    else
                    {
                        goodStorage = Apsim.Child(topLevelModel, typeof(IDataStore)) as Model;
                    }
                    var unwantedStorage = Apsim.Child(newSimulation, typeof(IDataStore)) as Model;
                    if (unwantedStorage != null)
                    {
                        Apsim.Delete(unwantedStorage);
                    }
                    if (goodStorage != null)
                    {
                        newSimulation.Children.Add(goodStorage);
                    }
                }
                else
                {
                    newSimulation = baseSimulation;
                }

                if (Name == null)
                {
                    newSimulation.Name = baseSimulation.Name;
                }
                else
                {
                    newSimulation.Name = Name;
                }
                newSimulation.Parent = null;
                Apsim.ParentAllChildren(newSimulation);
                replacementsToApply.ForEach(r => r.Replace(newSimulation));

                // Give the simulation the descriptors.
                newSimulation.Descriptors = Descriptors;

                return(newSimulation);
            }
            catch (Exception err)
            {
                var message = "Error in file: " + baseSimulation.FileName + " Simulation: " + Name;
                throw new Exception(message, err);
            }
        }