public Atombindung(Element element, int anzahlAtome) { Bestandteile = new List <Element[]>(); ChemischeFormel += (anzahlAtome == 1) ? element.Symol : element.Symol + UnicodeHelfer.GetSubscriptOfNumber(anzahlAtome); Name = (anzahlAtome == 1) ? element.Name : NomenklaturHelfer.Praefix(anzahlAtome) + element.Name.ToLower(); AddBestandteil(element, anzahlAtome); AnzahlAtome = anzahlAtome; //Name = GeneriereNameErsterOrdnung(); }
public Salz(Kation kation, Anion anion) { Kation = kation; Anion = anion; (int anzahlKation, int anzahlAnionen)benoetigeMolekuehle = Ion.BerechneAnzahlMolekuele(kation, anion); Kation.Molekuel.Anzahl = benoetigeMolekuehle.anzahlKation; Anion.Molekuel.Anzahl = benoetigeMolekuehle.anzahlAnionen; if (Anion.Molekuel.Atombindung.IstElementbindung()) { if (!String.IsNullOrEmpty(Anion.Molekuel.Atombindung.ErhalteElement().Wurzel)) { Name = Kation.Molekuel.Atombindung.Name + Anion.Molekuel.Atombindung.ErhalteElement().Wurzel.ToLower() + "id"; } else { Name = Kation.Molekuel.Atombindung.Name + Anion.Molekuel.Atombindung.ErhalteElement().Name.ToLower() + "id"; } } else { Name = Kation.Molekuel.Atombindung.Name + Anion.Molekuel.Atombindung.Name.ToLower(); } if (Kation.Molekuel.Anzahl > 1) { if (Kation.Molekuel.Atombindung.IstElementbindung()) { ChemischeFormel += $"{Kation.Molekuel.Atombindung.ChemischeFormel}{UnicodeHelfer.GetSubscriptOfNumber(Kation.Molekuel.Anzahl)}"; } else { ChemischeFormel += $"({Kation.Molekuel.Atombindung.ChemischeFormel}){UnicodeHelfer.GetSubscriptOfNumber(Kation.Molekuel.Anzahl)}"; } } else { ChemischeFormel += $"{Kation.Molekuel.Atombindung.ChemischeFormel}"; } if (Anion.Molekuel.Anzahl > 1) { if (UnicodeHelfer.GetNumberOfSubscript(Anion.Molekuel.Atombindung.ChemischeFormel.Last()) != -1) { ChemischeFormel += $"({Anion.Molekuel.Atombindung.ChemischeFormel}){UnicodeHelfer.GetSubscriptOfNumber(Anion.Molekuel.Anzahl)}"; } else { ChemischeFormel += $"{Anion.Molekuel.Atombindung.ChemischeFormel}{UnicodeHelfer.GetSubscriptOfNumber(Anion.Molekuel.Anzahl)}"; } } else { ChemischeFormel += $"{Anion.Molekuel.Atombindung.ChemischeFormel}"; } }
public string GeneriereChemischeFormelAusBestandteilen(List <Element[]> bestandteile = null, bool fuerAnzeige = false) { string chemischeFormel = null; if (bestandteile == null) { bestandteile = Bestandteile; } int anzahlAktuellerBestandteil = 1; for (int zaehler = 0; zaehler < bestandteile.Count; zaehler++) { // Erhalte das aktuelle Bestandteil Element[] bestandteil = bestandteile[zaehler]; // Überprüfe, ob es das letze Bestandteil in der Sequenz ist if (zaehler != bestandteile.Count - 1) { // Es gibt noch weitere bestandteile. Überprüfe, ob es sich ums selbe Bestandteil handelt if (bestandteil.Length == bestandteile[zaehler + 1].Length) { // Überprüfe, ob die sequenz identisch ist bool identisch = true; for (int cnt = 0; cnt < bestandteil.Length; cnt++) { if (bestandteil[cnt].Symol.Equals(bestandteile[zaehler + 1][cnt].Symol) == false) { identisch = false; } } if (identisch) { anzahlAktuellerBestandteil++; continue; } } } // Der nächste Bestandteil unterschiedet sich von diesem => Erstelle die Formel für dieses Molekül // Überprüfe, ob sich um eine Elementarbindung handelt if (bestandteil.Length == 1) { chemischeFormel += (anzahlAktuellerBestandteil == 1) ? bestandteil[0].Symol : $"{bestandteil[0].Symol}{UnicodeHelfer.GetSubscriptOfNumber(anzahlAktuellerBestandteil)}"; } else { string subChemischeFormel = null; int anzahlAktuellerSubBestandteil = 1; for (int cnt = 0; cnt < bestandteil.Length; cnt++) { if (cnt + 1 != bestandteil.Length) { if (bestandteil[cnt].Symol.Equals(bestandteil[cnt + 1].Symol)) { anzahlAktuellerSubBestandteil++; continue; } } subChemischeFormel += (anzahlAktuellerSubBestandteil == 1) ? bestandteil[cnt].Symol : $"{bestandteil[cnt].Symol}{UnicodeHelfer.GetSubscriptOfNumber(anzahlAktuellerSubBestandteil)}"; } if (fuerAnzeige) { chemischeFormel += (anzahlAktuellerBestandteil == 1) ? subChemischeFormel : $"({subChemischeFormel}){UnicodeHelfer.GetSubscriptOfNumber(anzahlAktuellerBestandteil)}"; } else { chemischeFormel += $"({subChemischeFormel}){UnicodeHelfer.GetSubscriptOfNumber(anzahlAktuellerBestandteil)}"; } } // Bestandteile zurücksetzen anzahlAktuellerBestandteil = 1; } return(chemischeFormel); }