private static T BuildTreeOptions <T>(TreeRingManager manager) where T : Tree, new()
        {
            var phase = GetTreePhase();

            if (!phase.HasValue)
            {
                return(null);
            }

            var type = GetTreeType();

            if (!type.HasValue)
            {
                return(null);
            }

            var waterDemand = GetTreeWaterDemand(type.Value);

            if (!waterDemand.HasValue)
            {
                return(null);
            }

            var speciesList = GetSpeciesList(waterDemand.Value, type.Value);

            if (!speciesList.Any())
            {
                return(null);
            }

            var species = GetTreeSpecies(speciesList);

            if (string.IsNullOrEmpty(species))
            {
                return(null);
            }

            var maxSpeciesHeight = (float)speciesList[species];
            var height           = GetTreeHeight(phase.Value, maxSpeciesHeight);

            if (!height.HasValue)
            {
                return(null);
            }

            var id = GetTreeId(manager);

            if (string.IsNullOrEmpty(id))
            {
                return(null);
            }

            return(new T
            {
                Phase = phase.Value,
                TreeType = type.Value,
                WaterDemand = waterDemand.Value,
                Species = species,
                Height = height.Value,
                ID = id
            });
        }
        private static string GetTreeId(TreeRingManager manager)
        {
            var ed = Application.DocumentManager.MdiActiveDocument.Editor;

            return(ed.PromptForString("\nEnter tree ID: ", manager.ManagedObjects.Count.ToString()));
        }
        public static void CopyTree()
        {
            try
            {
                StructuresExtensionApplication.Current.Logger.LogCommand(typeof(TreeRingCommands), nameof(CopyTree));

                Document acDoc = Application.DocumentManager.MdiActiveDocument;

                using (Transaction acTrans = acDoc.TransactionManager.StartTransaction())
                {
                    PromptStringOptions pStrOptsPlot = new PromptStringOptions("\nEnter tree ID: ")
                    {
                        AllowSpaces = false
                    };
                    PromptResult pStrResPlot = acDoc.Editor.GetString(pStrOptsPlot);
                    if (pStrResPlot.Status != PromptStatus.OK)
                    {
                        acTrans.Abort();
                        return;
                    }

                    string id = pStrResPlot.StringResult;

                    TreeRingManager treeRingManager = DataService.Current.GetStore <StructureDocumentStore>(acDoc.Name).GetManager <TreeRingManager>();
                    Tree            treeToBeCopied  = treeRingManager.ManagedObjects.FirstOrDefault(t => t.ID == id);
                    if (treeToBeCopied == null)
                    {
                        StructuresExtensionApplication.Current.Logger.Entry($"No tree found matching ID {id}",
                                                                            Severity.Warning);
                        acTrans.Abort();
                        return;
                    }

                    PromptPointOptions pPtOpts = new PromptPointOptions("\nEnter location: ");
                    PromptPointResult  pPtRes  = acDoc.Editor.GetPoint(pPtOpts);
                    while (pPtRes.Status == PromptStatus.OK)
                    {
                        Tree newTree = new Tree
                        {
                            Height      = treeToBeCopied.Height,
                            Phase       = treeToBeCopied.Phase,
                            Species     = treeToBeCopied.Species,
                            TreeType    = treeToBeCopied.TreeType,
                            WaterDemand = treeToBeCopied.WaterDemand,
                            ID          = treeRingManager.ManagedObjects.Count.ToString(),
                            Location    = new Point3d(pPtRes.Value.X, pPtRes.Value.Y, 0)
                        };

                        newTree.AddLabel();

                        treeRingManager.AddTree(newTree);

                        acDoc.TransactionManager.QueueForGraphicsFlush();
                        pPtRes = acDoc.Editor.GetPoint(pPtOpts);
                    }

                    acTrans.Commit();
                }
            }
            catch (System.Exception e)
            {
                StructuresExtensionApplication.Current.Logger.LogException(e);
                throw;
            }
        }