private void BuildNodes(TreeNode rootNode, IChemObject[] objects) { foreach (IChemObject obj in objects) { TreeNode node; if (obj is IChemSequence) { IChemSequence seq = (IChemSequence)obj; node = new TreeNode(obj.GetType().Name + ":" + seq.ID); BuildNodes(node, seq.ChemModels); } else if (obj is IChemModel) { IChemModel mdl = (IChemModel)obj; node = new TreeNode(mdl.GetType().Name + ":" + mdl.ID); if (mdl.Crystal != null) { node.Nodes.Add(mdl.Crystal.GetType().Name + ":" + mdl.Crystal.ID); } else { node.Nodes.Add("ICrystal:null"); } if (mdl.RingSet != null) { node.Nodes.Add(mdl.RingSet.GetType().Name + ":" + mdl.RingSet.ID); } else { node.Nodes.Add("IRingSet:null"); } if (mdl.SetOfReactions != null) { node.Nodes.Add(mdl.SetOfReactions.GetType().Name + ":" + mdl.SetOfReactions.ID); } else { node.Nodes.Add("ISetOfReactions:null"); } BuildNodes(node, mdl.SetOfMolecules.Molecules); } else if (obj is IMolecule) { IMolecule mol = (IMolecule)obj; node = new TreeNode(mol.GetType().Name + ":" + mol.ID); BuildNodes(node, mol.Atoms); BuildNodes(node, mol.Bonds); } else if (obj is IAtom) { IAtom atom = (IAtom)obj; node = new TreeNode(atom.GetType().Name + ":" + atom.ID); } else if (obj is IBond) { IBond bond = (IBond)obj; node = new TreeNode(bond.GetType().Name + ":" + bond.ID); } else { node = new TreeNode(obj.GetType().Name + ":" + obj.ID); } rootNode.Nodes.Add(node); } }