public RxnExtent(RxnExtent original) { if (original != null) { m_Owner = original.Owner; this.Value = original.Value; this.Specie = original.Specie; } }
public static DialogResult Show(SimpleReaction curReaction, SimpleReaction newReaction, string title, string message, string newReactionTitle, bool bSeq, bool bExtentAndHOR) { FrmChangeDialogue frmCurrent = frm.Visible ? new FrmChangeDialogue() : frm; frmCurrent.SuspendLayout(); frmCurrent.txtMessage.Text = message; frmCurrent.grpNewReaction.Text = newReactionTitle; frmCurrent.Text = title; frmCurrent.SetReactions(curReaction, newReaction, bSeq, bExtentAndHOR); frmCurrent.ResumeLayout(); return frmCurrent.ShowDialog(); }
public FrmBalanceOptions(Matrix.RemovalInfo info, SimpleReaction rxn) { baseInfo = info; int chkSpacing = 23; int extraFormSpace = 170 - 23; int chkX = 6, chkY = 19; InitializeComponent(); if (info.DegreesOfFreedom > 1) lblInfo.Text = "The selected reaction is under-constrained, and as such requires that some compounds be removed from the reaction to allow autbalancing. Please select " + info.DegreesOfFreedom + " compounds to remove."; else lblInfo.Text = "The selected reaction is under-constrained, and as such requires that a compound be removed from the reaction to allow autbalancing. Please select which compound to remove."; List<Compound> products = rxn.OrderedProducts; List<Compound> reactants = rxn.OrderedReactants; int longestLength = products.Count > reactants.Count - 1 ? products.Count : reactants.Count - 1; this.Height = extraFormSpace + longestLength * chkSpacing; for (int i = 0; i < reactants.Count - 1; i++) { CheckBox chk = new CheckBox(); grpReactants.Controls.Add(chk); chk.AutoSize = true; chk.UseVisualStyleBackColor = true; chk.Name = "chkOption" + i; chk.Text = reactants[i + 1].Symbol; chk.Enabled = info.m_IfRemoved[i].m_bCanRemove; chk.Location = new Point(chkX, chkY + i * chkSpacing); chk.TabIndex = i; chk.CheckedChanged += new EventHandler(chk_CheckedChanged); m_Checkboxes.Add(chk); } for (int i = 0; i < products.Count; i++) { CheckBox chk = new CheckBox(); grpProducts.Controls.Add(chk); chk.AutoSize = true; chk.UseVisualStyleBackColor = true; chk.Name = "chkOption" + (i + reactants.Count - 1); chk.Text = products[i].Symbol; chk.Enabled = info.m_IfRemoved[i + reactants.Count - 1].m_bCanRemove; chk.Location = new Point(chkX, chkY + i * chkSpacing); chk.TabIndex = i + reactants.Count - 1; chk.CheckedChanged += new EventHandler(chk_CheckedChanged); m_Checkboxes.Add(chk); } }
public FrmBalanceOptions2(SimpleReaction rxn, List<Compound> extraComps) { m_OriginalMatrix = rxn.GetBalanceMatrix(extraComps); m_OriginalMatrix.RowReduce(); m_MinValues = new Fraction[m_OriginalMatrix.Columns - 1]; m_MaxValues = new Fraction[m_OriginalMatrix.Columns - 1]; for (int i = 0; i < m_MinValues.Length; i++) { m_MinValues[i] = Fraction.MaxValue; if (m_OriginalMatrix.CanGoNegative(i)) m_MaxValues[i] = Fraction.MinValue; else m_MaxValues[i] = 0; } CalculateAbsoluteMinMaxValues(m_OriginalMatrix, new List<int>()); InitializeComponent(); int c = m_OriginalMatrix.Columns - 1 - m_OriginalMatrix.Rank; bool[] changeables = m_OriginalMatrix.ColumnsRemoveable(); if (c > 1) lblInfo.Text = "The selected reaction is under-constrained, and as such requires that some compounds have specified coefficients to allow autbalancing. Please specify " + c + " values to balance."; else lblInfo.Text = "The selected reaction is under-constrained, and as such requires that a compound have a specified coefficient to allow autbalancing. Please specify a value."; List<Compound> products = rxn.OrderedProducts; List<Compound> reactants = rxn.OrderedReactants; int longestLength = products.Count > reactants.Count - 1 ? products.Count : reactants.Count - 1; if (extraComps.Count > longestLength) longestLength = extraComps.Count; this.Height = extraFormSpace + longestLength * chkSpacing; PopulateGroupBox(grpReactants, reactants, 0, changeables, 1); PopulateGroupBox(grpProducts, products, reactants.Count - 1, changeables, 0); if (extraComps.Count != 0) { lblNote.Text = "Note that a negative value in the third group indicates the compound will be a reactant, while a positive value indicates it will be a product."; int extraWidth = grpProducts.Right - grpReactants.Right; this.Width += extraWidth; GroupBox grpExtras = new GroupBox(); grpExtras.Text = "Autobalance Added Compounds"; this.Controls.Add(grpExtras); grpExtras.Top = grpProducts.Top; grpExtras.Left = grpProducts.Left + extraWidth; grpExtras.Width = grpProducts.Width; grpExtras.Height = grpProducts.Height; PopulateGroupBox(grpExtras, extraComps, reactants.Count - 1 + products.Count, changeables, 0); } SetInitialValues(); m_bDoOnValueChanged = true; }
void frm_ReactionChanged(FrmReaction form, SimpleReaction reaction) { TreeNode frmNode = (TreeNode)form.Tag; TreeNode n = FindTreeNode(form, reaction); if (n != null) n.Text = reaction.ToString(); }
void frm_ReactionAdded(FrmReaction form, SimpleReaction reaction) { if (form == ActiveMdiChild) UpdateUsedSpecies(); TreeNode newNode = new TreeNode(reaction.ToString()); newNode.Tag = reaction; ((TreeNode)form.Tag).Nodes.Add(newNode); }
protected TreeNode FindTreeNode(FrmReaction form, SimpleReaction reaction) { TreeNode f = (TreeNode)form.Tag; foreach (TreeNode r in f.Nodes) if (r.Tag == reaction) return r; return null; }
void frm_ReactionRemoved(FrmReaction form, SimpleReaction reaction) { if (form == ActiveMdiChild) UpdateUsedSpecies(); TreeNode t = FindTreeNode(form, reaction); if (t != null) t.Remove(); }
public SimpleReaction AddReaction(SimpleReaction rxn, int location) { ListViewItem lvi = new ListViewItem(); lvi.SubItems.AddRange(new string[] { "", "", "", "" }); if (location == 0 && m_Sources != null) lstReactions.Items.Insert(1, lvi); else if (location > MaxReactionLocation) lstReactions.Items.Insert(MaxReactionLocation, lvi); else if (location >= 0) lstReactions.Items.Insert(location, lvi); else lstReactions.Items.Insert(MaxReactionLocation, lvi); SimpleReaction newRxn = rxn.Clone(lvi); newRxn.SequenceChanged += new EventHandler(rxn_SequenceChanged); newRxn.Changed += new EventHandler(rxn_Changed); newRxn.FireChanged(); UpdateReactionNumbers(); if (ReactionAdded != null) ReactionAdded(this, rxn); return newRxn; }
/// <summary> /// Creates a backup of this reaction that can be accessed using Revert() /// </summary> public void Backup() { m_Original = Clone(); }
public void SelectReaction(SimpleReaction rxn) { if (rxn == null) { lstReactions.SelectedItems.Clear(); return; } if (rxn.LVI == null || !lstReactions.Items.Contains(rxn.LVI) || lstReactions.SelectedItems.Contains(rxn.LVI)) return; lstReactions.SelectedItems.Clear(); rxn.LVI.Selected = true; }
public MessageFrmReaction(string title, FrmReaction owner, SimpleReaction rxn) : base(title) { m_owner = owner; m_rxn = rxn; }
protected void LoadReaction(SimpleReaction rxn) { m_bLoading = true; if (m_CurrentReaction != null) { m_CurrentReaction.Changed -= new EventHandler(currentReactionChanged); m_CurrentReaction.ReactantsChanged -= new EventHandler(rxn_ReactantsChanged); m_CurrentReaction.ProductsChanged -= new EventHandler(rxn_ReactantsChanged); } m_CurrentReaction = rxn; txtReactants.Visible = txtProducts.Visible = comboDirection.Visible = true; txtFormula.Visible = false; if (SelectedReactionChanged != null) SelectedReactionChanged(this, new EventArgs()); if (rxn == null) { SetPanelEnables(pnlReaction, false); //pnlReaction.Enabled = false; txtReactants.Text = txtProducts.Text = ""; comboDirection.SelectedIndex = -1; comboExtentType.SelectedIndex = -1; comboExtentSpecie.SelectedIndex = -1; comboHORSpecie.SelectedIndex = -1; chkHOROverride.Checked = false; numSequence.Text = ""; chkEnabled.Checked = false; m_bLoading = false; return; } rxn.Changed += new EventHandler(currentReactionChanged); rxn.ReactantsChanged += new EventHandler(rxn_ReactantsChanged); rxn.ProductsChanged += new EventHandler(rxn_ReactantsChanged); btnCopy.Enabled = btnMoveDown.Enabled = btnMoveUp.Enabled = btnRemove.Enabled = true; if (rxn.UseOriginalString) { txtReactants.Visible = txtProducts.Visible = comboDirection.Visible = false; txtFormula.Visible = true; txtFormula.Text = rxn.ToString(); } /*if (string.IsNullOrEmpty(rxn.GetProductsString())) SetWaitingText(txtProducts, "Products"); else { txtProducts.Text = rxn.GetProductsString(); txtProducts.TextAlign = HorizontalAlignment.Left; txtProducts.ForeColor = System.Drawing.SystemColors.WindowText; txtProducts.Tag = true; } if (string.IsNullOrEmpty(rxn.GetReactantsString())) SetWaitingText(txtReactants, "Reactants"); else { txtReactants.TextAlign = HorizontalAlignment.Right; txtReactants.Text = rxn.GetReactantsString(); txtReactants.ForeColor = System.Drawing.SystemColors.WindowText; txtReactants.Tag = true; }*/ SetPanelEnables(pnlReaction, true); comboExtentSpecie.Enabled = !chkFirstReactant.Checked; numSequence.Enabled = chkSequence.Checked; SetHOREnabled(rxn.CustomHeatOfReaction); txtReactants.Text = rxn.GetReactantsString(); txtProducts.Text = rxn.GetProductsString(); RepopulateSpecies(false); comboDirection.SelectedIndex = (int)rxn.Direction; comboExtentType.SelectedIndex = (int)rxn.ExtentType; chkHOROverride.Checked = rxn.CustomHeatOfReaction; numExtentValue.Text = rxn.ExtentInfo.Value.ToString(); chkEnabled.Checked = rxn.Enabled; txtComment.Text = rxn.Comment; if (chkSequence.Checked) { numSequence.Value = Math.Min(Math.Max(rxn.Sequence, 1), sMaxSequences); numSequence.Text = numSequence.Value.ToString(); } //pnlReaction.Enabled = true; m_bLoading = false; btnBalance.Enabled = rxn.CanBalance; }
protected SimpleReaction CreateReaction() { ListViewItem lvi = new ListViewItem(); lvi.SubItems.AddRange(new string[] { "", "", "", "" }); lstReactions.Items.Insert(MaxReactionLocation, lvi); SimpleReaction rxn = new SimpleReaction(lvi); rxn.Changed += new EventHandler(rxn_Changed); rxn.SequenceChanged += new EventHandler(rxn_SequenceChanged); rxn_Changed(rxn, new EventArgs()); rxn_SequenceChanged(rxn, new EventArgs()); UpdateReactionNumbers(); rxn.Initialised = true; return rxn; }
public SimpleReaction Clone(ListViewItem newLVI) { SimpleReaction ret = new SimpleReaction(newLVI); ret.SetRegex(s_GeneralReactionRegex.Match(this.ToSaveString(true)), new MessageSource("SimpleReaction.Clone"), "Clone"); /*SimpleReaction ret = (SimpleReaction) this.MemberwiseClone(); ret.LVI = newLVI; //Items which must make their own clones: ret.m_Extent = m_Extent.Clone(ret); ret.m_OrderedProducts = new List<Compound>(m_OrderedProducts); ret.m_OrderedReactants = new List<Compound>(m_OrderedReactants); ret.m_Products = new Dictionary<Compound, Fraction>(m_Products); ret.m_Reactants = new Dictionary<Compound, Fraction>(m_Reactants); ret.m_Unbalanced = new Dictionary<Element, Fraction>(m_Unbalanced); ret.Changed = null; ret.Changed += new EventHandler(ret.UpdateStatus);*/ return ret; }
protected void SetReactions(SimpleReaction curReaction, SimpleReaction newReaction, bool bSeq, bool bExtentAndHOR) { ChangeGeneric(false); Font BoldFont = new Font(txtCurReactants.Font, FontStyle.Bold); bool HOR = bExtentAndHOR && (curReaction.CustomHeatOfReaction || newReaction.CustomHeatOfReaction); //Current Reaction: txtCurReactants.Text = curReaction.GetReactantsString(); txtCurDirection.Text = curReaction.DirectionString; txtCurProducts.Text = curReaction.GetProductsString(); txtCurExtent.Text = curReaction.ExtentInfo.ToString(); if (curReaction.CustomHeatOfReaction) txtCurHOR.Text = curReaction.HeatOfReactionString; else txtCurHOR.Text = "HeatOfReaction: Default"; if (bSeq) txtCurSeq.Text = "Sequence: " + curReaction.Sequence; //New Reaction: txtNewReactants.Text = newReaction.GetReactantsString(); txtNewDirection.Text = newReaction.DirectionString; txtNewProducts.Text = newReaction.GetProductsString(); txtNewExtent.Text = newReaction.ExtentInfo.ToString(); if (newReaction.CustomHeatOfReaction) txtNewHOR.Text = newReaction.HeatOfReactionString; else txtNewHOR.Text = "HeatOfReaction: Default"; if (bSeq) txtNewSeq.Text = "Sequence: " + newReaction.Sequence; //Customise the layout: txtCurHOR.Visible = txtNewHOR.Visible = HOR; txtCurSeq.Visible = txtNewSeq.Visible = bSeq; txtCurExtent.Visible = txtNewExtent.Visible = bExtentAndHOR; txtCurSeq.Top = txtNewSeq.Top = HOR ? sSeqLowTop : txtCurHOR.Top; grpCurrentReaction.Height = grpNewReaction.Height = sMaxGrpHeight - ((HOR ? 0 : 1) + (bSeq ? 0 : 1) + (bExtentAndHOR ? 0 : 1)) * sHeightPerBox; grpNewReaction.Top = grpCurrentReaction.Bottom + sPadding; this.MaximumSize = this.MinimumSize = new Size(this.Width, sMaxFrmHeight - 2 * ((HOR ? 0 : 1) + (bSeq ? 0 : 1) + (bExtentAndHOR ? 0 : 1)) * sHeightPerBox); this.Height = sMaxFrmHeight - 2 * ((HOR ? 0 : 1) + (bSeq ? 0 : 1) + (bExtentAndHOR ? 0 : 1)) * sHeightPerBox; //Width: Graphics gfx = txtCurReactants.CreateGraphics(); float w1 = gfx.MeasureString(txtCurReactants.Text, BoldFont).Width; float w2 = gfx.MeasureString(txtCurProducts.Text, BoldFont).Width; float w3 = gfx.MeasureString(txtNewReactants.Text, BoldFont).Width; float w4 = gfx.MeasureString(txtNewProducts.Text, BoldFont).Width; int MaxW = (int)Math.Max(w1, Math.Max(w2, Math.Max(w3, w4))); if (MaxW > sMaxWidth) MaxW = sMaxWidth; if (MaxW < sMinWidth) MaxW = sMinWidth; txtCurProducts.Width = txtCurReactants.Width = txtNewProducts.Width = txtNewReactants.Width = MaxW; txtCurDirection.Left = txtNewDirection.Left = txtCurReactants.Right + sPadding; txtCurProducts.Left = txtNewProducts.Left = txtCurDirection.Right + sPadding; grpCurrentReaction.Width = grpNewReaction.Width = 2 * MaxW + txtCurDirection.Width + 4 * sPadding; this.MinimumSize = this.MaximumSize = new Size(grpCurrentReaction.Width + sExtraFrmPadding, this.Height); this.Width = grpCurrentReaction.Width + sExtraFrmPadding; //Format text boxes: //Alignment: txtCurReactants.SelectAll(); txtNewReactants.SelectAll(); txtCurDirection.SelectAll(); txtNewDirection.SelectAll(); txtCurProducts.SelectAll(); txtNewProducts.SelectAll(); txtCurReactants.SelectionAlignment = txtNewReactants.SelectionAlignment = txtCurProducts.SelectionAlignment = txtNewProducts.SelectionAlignment = txtCurDirection.SelectionAlignment = txtNewDirection.SelectionAlignment = HorizontalAlignment.Center; #region Bold changes in reactants / products / direction: if (!curReaction.ReactantsOk || !curReaction.ProductsOk) { //Do a straight string comparison: if (txtCurReactants.Text != txtNewReactants.Text) { HighlightText(txtCurReactants); HighlightText(txtNewReactants); } } else { //Compare each coefficient: foreach (Compound c in curReaction.OrderedReactants) if (!newReaction.OrderedReactants.Contains(c)) { txtCurReactants.Select(curReaction.ReactantIndex(c), curReaction.Reactants[c].ToString().Length + c.ToString().Length + 1); HighlightText(txtCurReactants); } else if (newReaction.Reactants[c] != curReaction.Reactants[c]) { txtCurReactants.Select(curReaction.ReactantIndex(c), curReaction.Reactants[c].ToString().Length); txtNewReactants.Select(newReaction.ReactantIndex(c), newReaction.Reactants[c].ToString().Length); HighlightText(txtCurReactants); HighlightText(txtNewReactants); } foreach (Compound c in newReaction.OrderedReactants) if (!curReaction.OrderedReactants.Contains(c)) { txtNewReactants.Select(newReaction.ReactantIndex(c), newReaction.Reactants[c].ToString().Length + c.ToString().Length + 1); HighlightText(txtNewReactants); } } //Bold changes in products: if (!curReaction.ProductsOk || !curReaction.ProductsOk) { //Do a straight string comparison: if (txtCurProducts.Text != txtNewProducts.Text) { HighlightText(txtCurProducts); HighlightText(txtNewProducts); } } else { //Compare each coefficient: foreach (Compound c in curReaction.OrderedProducts) if (!newReaction.OrderedProducts.Contains(c)) { txtCurProducts.Select(curReaction.ProductIndex(c), curReaction.Products[c].ToString().Length + c.ToString().Length + 1); HighlightText(txtCurProducts); } else if (newReaction.Products[c] != curReaction.Products[c]) { txtCurProducts.Select(curReaction.ProductIndex(c), curReaction.Products[c].ToString().Length); txtNewProducts.Select(newReaction.ProductIndex(c), newReaction.Products[c].ToString().Length); HighlightText(txtCurProducts); HighlightText(txtNewProducts); } foreach (Compound c in newReaction.OrderedProducts) if (!curReaction.OrderedProducts.Contains(c)) { txtNewProducts.Select(newReaction.ProductIndex(c), newReaction.Products[c].ToString().Length + c.ToString().Length + 1); HighlightText(txtNewProducts); } } //Direction if (txtCurDirection.Text != txtNewDirection.Text) { HighlightText(txtCurDirection); HighlightText(txtNewDirection); } #endregion Formula #region Extent if (curReaction.ExtentType != newReaction.ExtentType) { txtCurExtent.SelectAll(); txtNewExtent.SelectAll(); HighlightText(txtCurExtent); HighlightText(txtNewExtent); } else if (txtCurExtent.Text != txtNewExtent.Text) { //We only want to bold the stuff after "Extent: [Type]" txtCurExtent.Select(curReaction.ExtentInfo.StartString.Length, txtCurExtent.Text.Length - curReaction.ExtentInfo.StartString.Length); txtNewExtent.Select(newReaction.ExtentInfo.StartString.Length, txtNewExtent.Text.Length - newReaction.ExtentInfo.StartString.Length); HighlightText(txtCurExtent); HighlightText(txtNewExtent); } #endregion Extent #region HOR if (curReaction.CustomHeatOfReaction != newReaction.CustomHeatOfReaction) { txtCurHOR.SelectAll(); txtNewHOR.SelectAll(); HighlightText(txtCurHOR); HighlightText(txtNewHOR); } else if (HOR) { Match curMatch = SimpleReaction.s_HORRegex.Match(curReaction.HeatOfReactionString); Match newMatch = SimpleReaction.s_HORRegex.Match(newReaction.HeatOfReactionString); foreach (string s in SimpleReaction.s_HORRegex.GetGroupNames()) { if (curMatch.Groups[s].Value != newMatch.Groups[s].Value) { if (curMatch.Groups[s].Success) { txtCurHOR.Select(curMatch.Groups[s].Index, curMatch.Groups[s].Length); HighlightText(txtCurHOR); } if (newMatch.Groups[s].Success) { txtNewHOR.Select(newMatch.Groups[s].Index, newMatch.Groups[s].Length); HighlightText(txtNewHOR); } } } #region Old way of going about it /*if (curReaction.HeatOfReactionType != newReaction.HeatOfReactionType) //Type { txtCurHOR.Select(curMatch.Groups["Type"].Index, curMatch.Groups["Type"].Length); txtNewHOR.Select(newMatch.Groups["Type"].Index, newMatch.Groups["Type"].Length); txtCurHOR.SelectionFont = txtNewHOR.SelectionFont = BoldFont; } if (curReaction.HeatOfReactionValue != newReaction.HeatOfReactionValue) //Value { txtCurHOR.Select(curMatch.Groups["Value"].Index, curMatch.Groups["Value"].Length); txtNewHOR.Select(newMatch.Groups["Value"].Index, newMatch.Groups["Value"].Length); txtCurHOR.SelectionFont = txtNewHOR.SelectionFont = BoldFont; } if (curReaction.HeatOfReactionSpecie != newReaction.HeatOfReactionSpecie) //Specie { txtCurHOR.Select(curMatch.Groups["Specie"].Index, curMatch.Groups["Specie"].Length); txtNewHOR.Select(newMatch.Groups["Specie"].Index, newMatch.Groups["Specie"].Length); txtCurHOR.SelectionFont = txtNewHOR.SelectionFont = BoldFont; } if (curReaction.HeatOfReactionConditions != newReaction.HeatOfReactionConditions) //Conditions { txtCurHOR.Select(curMatch.Groups["Cond"].Index, curMatch.Groups["Cond"].Length); txtNewHOR.Select(newMatch.Groups["Cond"].Index, newMatch.Groups["Cond"].Length); txtCurHOR.SelectionFont = txtNewHOR.SelectionFont = BoldFont; } else if (curReaction.HeatOfReactionConditions == TPConditions.Custom) { if (curReaction.HeatOfReactionT != newReaction.HeatOfReactionT) { txtCurHOR.Select(curMatch.Groups["T"].Index, curMatch.Groups["T"].Length); txtNewHOR.Select(newMatch.Groups["T"].Index, newMatch.Groups["T"].Length); txtCurHOR.SelectionFont = txtNewHOR.SelectionFont = BoldFont; } if (curReaction.HeatOfReactionP != newReaction.HeatOfReactionP) { txtCurHOR.Select(curMatch.Groups["P"].Index, curMatch.Groups["P"].Length); txtNewHOR.Select(newMatch.Groups["P"].Index, newMatch.Groups["P"].Length); txtCurHOR.SelectionFont = txtNewHOR.SelectionFont = BoldFont; } }*/ #endregion } #endregion HOR #region Seq if (bSeq && curReaction.Sequence != newReaction.Sequence) { txtCurSeq.SelectAll(); txtNewSeq.SelectAll(); HighlightText(txtCurSeq); HighlightText(txtNewSeq); } #endregion Seq }
public bool ContainsReaction(SimpleReaction rxn) { foreach (ListViewItem lvi in lstReactions.Items) if (lvi.Tag == rxn) return true; return false; }
public RxnExtent Clone(SimpleReaction newOwner) { RxnExtent ret = (RxnExtent)this.MemberwiseClone(); ret.m_Owner = newOwner; return ret; }