// 按照指定方式获取父类群。 public static IReadOnlyList <Taxon> GetParents(this Taxon taxon, GetParentsOption option) { if (taxon is null) { throw new ArgumentNullException(); } // List <Taxon> result = new List <Taxon>(); if (!taxon.IsRoot) { if (option == GetParentsOption.EditMode) { // 上溯到任何具名分类阶元类群,保留任何类群 result.AddRange(taxon.GetParents( TaxonFilter.Any, TaxonFilter.Named | TaxonFilter.AnyRank, includeTermination: true, skipParaphyly: false)); // 如果没有上溯到任何主要分类阶元类群,直接上溯到顶级类群,保留任何类群 if (result.Count <= 0) { result.AddRange(taxon.GetParents( TaxonFilter.Any, TaxonFilter.None, includeTermination: true, skipParaphyly: false)); } } else if (option == GetParentsOption.Least) { // 首先上溯到任何具名类群,保留任何具名类群,不跳过并系群 result.AddRange(taxon.GetParents( TaxonFilter.Named | TaxonFilter.AnyRank, TaxonFilter.Named | TaxonFilter.AnyRank, includeTermination: true, skipParaphyly: false)); // 如果上溯到任何未指定分级类群或演化支类群,继续上溯到任何主要或次要分类阶元类群,保留任何具名类群,跳过并系群 if (result.Count > 0) { Taxon parent = result[^ 1];
// 更新父类群。 private void _UpdateParents() { Taxon currentTaxon = Common.CurrentTaxon; if (currentTaxon.IsRoot) { taxonButtonGroup_Parents.Clear(); } else { List <Taxon> parents = new List <Taxon>(currentTaxon.GetParents(_GetParentsOption)); if (parents.Count > 0) { parents.Reverse(); } parents.Add(currentTaxon); Common.UpdateTaxonListAndGroupByRank(taxonButtonGroup_Parents, parents); } }