//========================================================================================= // Generation functions // // méthode pour retourner la génération d'un taxon public int getGeneration() { int level = 0; Taxon current = this; while (current != null) { level++; current = current._Father; } return(level); }
//--------------------------------------------------------------------------------- public string getFullName() { string fullName = Name; Taxon current = _Father; while (current != null) { fullName = current.Name + "|" + fullName; current = current._Father; } return(fullName); }
//------------------------------------------ public Taxon FindTaxonByFullName(string _fullname) { if (_fullname == null) { return(null); } string[] separate = _fullname.ToLower().Split(new char[] { '|' }); if (separate == null || separate.Count() < 1) { return(null); } if (separate[0] != Name.ToLower()) { return(null); } if (separate.Count() == 1) { return(this); } Taxon current = this; int index = 1; while (index < separate.Count()) { bool found = false; foreach (Taxon child in current._Children) { if (child.Name.ToLower() == separate[index]) { index++; if (index == separate.Count()) { return(current); } current = child; found = true; break; } } if (!found) { return(null); } } return(null); }
//========================================================================================= // Children functions // //------------------------------------------ public Taxon FindTaxonByName(string _name) { if (Name.ToLower() == _name) { return(this); } foreach (Taxon child in _Children) { Taxon result = child.FindTaxonByName(_name); if (result != null) { return(result); } } return(null); }
//méthode pour retourner la liste des parents public void getAllParents(List <Taxon> _list, bool _includeFirst = true, bool _fromFatherToChild = true) { Taxon current = this; if (!_includeFirst) { current = current.Father; } while (current != null) { _list.Add(current); current = current._Father; } if (_fromFatherToChild) { _list.Reverse(); } }
//-------------------------------------------------------------------------------------- void ContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e) { if (SelectedItem == null || !(SelectedItem is Taxon)) { e.Cancel = true; return; } Taxon taxon = SelectedItem as Taxon; ToolStripMenuItem menuItem; ContextMenuStrip.Items.Clear(); menuItem = new ToolStripMenuItem("Goto " + taxon.DisplayName, null, new System.EventHandler(onGoto)); ContextMenuStrip.Items.Add(menuItem); menuItem = new ToolStripMenuItem("Select " + taxon.DisplayName, null, new System.EventHandler(onSelect)); ContextMenuStrip.Items.Add(menuItem); menuItem = new ToolStripMenuItem("Add " + taxon.DisplayName + " to favorite", null, new System.EventHandler(onAddFavorite)); ContextMenuStrip.Items.Add(menuItem); e.Cancel = false; }
//-------------------------------------------------------------------------------------- protected override void OnDrawItem(DrawItemEventArgs e) { Taxon taxon = null; if (e.Index >= 0 && e.Index < Items.Count) { taxon = Items[e.Index] as Taxon; } if (taxon == null) { base.OnDrawItem(e); return; } //Brush b = (e.Index & 1) == 0 ? Brushes.PapayaWhip : Brushes.PeachPuff; Brush b = Brushes.LightYellow; if ((e.State & DrawItemState.Selected) != 0) { b = Brushes.Gold; } else if (e.Index == MouseIndex) { b = Brushes.Khaki; } e.Graphics.FillRectangle(b, e.Bounds); e.Graphics.DrawString(taxon.DisplayName, Font, Brushes.Black, e.Bounds); Image image = TaxonImages.Manager.GetSmallImage(taxon); if (image != null) { Rectangle imageRect = e.Bounds; imageRect.X = imageRect.Right - imageRect.Height; imageRect.Width = imageRect.Height; e.Graphics.DrawImage(image, imageRect); } }
//-------------------------------------------------------------------------------------- public int IndexOf(Taxon _taxon) { return(Items.IndexOf(_taxon)); }
public FilterResult filterNonNommé(Taxon _taxon) { return((_taxon.Name == "non nommé") ? FilterResult.Yes : FilterResult.No); }
//------------------------------------------ //méthode qui rajoute un taxon à la liste des enfants (_children) public void AddChild(Taxon _child) { _child.Father = this; _Children.Add(_child); }