Exemplo n.º 1
0
        private void RemoveOldAtomsAndBond(NotifyCollectionChangedEventArgs e)
        {
            foreach (Molecule child in e.OldItems)
            {
                child.Parent = null;

                foreach (Atom atom in child.Atoms.ToList())
                {
                    AllAtoms.Remove(atom);
                }

                foreach (Bond bond in child.Bonds.ToList())
                {
                    AllBonds.Remove(bond);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adding molecules to  or removing from the model also adds the Atoms and Bonds
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Molecules_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:

                foreach (Molecule m in e.NewItems)
                {
                    foreach (Atom atom in m.Atoms)
                    {
                        if (!AllAtoms.Contains(atom))
                        {
                            AllAtoms.Add(atom);
                        }
                    }

                    foreach (Bond bond in m.Bonds)
                    {
                        if (!AllBonds.Contains(bond))
                        {
                            AllBonds.Add(bond);
                        }
                    }
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (Molecule m in e.OldItems)
                {
                    foreach (Atom atom in m.Atoms.ToList())
                    {
                        AllAtoms.Remove(atom);
                    }

                    foreach (Bond bond in m.Bonds.ToList())
                    {
                        AllBonds.Remove(bond);
                    }
                }
                break;
            }
        }
Exemplo n.º 3
0
        private void BondsOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (Bond bond in e.NewItems)
                {
                    bond.Parent = this;
                    AllBonds.Add(bond);
                }
                break;

            case NotifyCollectionChangedAction.Move:
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (Bond bond in e.OldItems)
                {
                    AllBonds.Remove(bond);
                    bond.Parent = null;
                }
                break;

            case NotifyCollectionChangedAction.Replace:
                foreach (Bond bond in e.NewItems)
                {
                    bond.Parent = this;
                    AllBonds.Add(bond);
                }
                foreach (Bond bond in e.OldItems)
                {
                    AllBonds.Remove(bond);
                    bond.Parent = null;
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                break;
            }
        }