コード例 #1
0
        protected void SetReactions(HXReaction curReaction, HXReaction newReaction)
        {
            ChangeGeneric(true);
            Font BoldFont = new Font(txtCurReactants.Font, FontStyle.Bold);

            txtCurGeneric.Text = curReaction.ToString();
            txtNewGeneric.Text = newReaction.ToString();

            Match curMatch = HXReaction.s_HXRegex.Match(txtCurGeneric.Text);
            Match newMatch = HXReaction.s_HXRegex.Match(txtNewGeneric.Text);
            string[] groups = new string[] { "Type", "Value", "Value2" };
            foreach (string s in groups)
            {
                Group curGroup = curMatch.Groups[s];
                Group newGroup = newMatch.Groups[s];
                if (curGroup.Value != newGroup.Value)
                {
                    if (curGroup.Success)
                    {
                        txtCurGeneric.Select(curGroup.Index, curGroup.Length);
                        HighlightText(txtCurGeneric);
                    }
                    if (newGroup.Success)
                    {
                        txtNewGeneric.Select(newGroup.Index, newGroup.Length);
                        HighlightText(txtNewGeneric);
                    }
                }
            }
        }
コード例 #2
0
ファイル: FrmReaction.cs プロジェクト: ChrisMoreton/Test3
    private void btnRemove_Click(object sender, EventArgs e)
    {
      if (lstReactions.SelectedItems.Count == 0)
        return;
      ListViewItem lvi = lstReactions.SelectedItems[0];
      lstReactions.SelectedItems[0].Remove();

      if (lvi.Tag is SimpleReaction)
      {
        SimpleReaction rxn = (SimpleReaction)lvi.Tag;
        if (ReactionRemoved != null)
          ReactionRemoved(this, rxn);
      }
      else if (lvi.Tag == m_HX)
      {
        lstReactions.Items.Remove(m_HX.LVI);
        m_HX = null;
      }
      else if (lvi.Tag == m_Sinks)
      {
        lstReactions.Items.Remove(m_Sinks.LVI);
        m_Sinks = null;
        if (SourcesSinksChanged != null)
          SourcesSinksChanged(this, new EventArgs());
      }
      else if (lvi.Tag == m_Sources)
      {
        lstReactions.Items.Remove(m_Sources.LVI);
        m_Sources = null;
        if (SourcesSinksChanged != null)
          SourcesSinksChanged(this, new EventArgs());
      }

      ChangeOccured();
      UpdateReactionNumbers();
    }
コード例 #3
0
ファイル: FrmReaction.cs プロジェクト: ChrisMoreton/Test3
    protected void ReadFile()
    {
      try
      {
        m_bLoading = true;

        Log.SetSource(new MessageFrmReaction(this.Title, this, null));

        byte[] buffer = new byte[m_File.Length];
        m_File.Read(buffer, 0, (int)m_File.Length);
        string contents = Encoding.Default.GetString(buffer);

        //Version:
        Match verMatch = s_FileVersionRegex.Match(contents);
        Version savedVersion = new Version(0, 0, 0, 0);
        if (verMatch.Success)
          try { savedVersion = new Version(verMatch.Groups["Version"].Value); }
          catch { }
        Version MinVersion = new Version("1.0.17");

        //General comments:
        StringBuilder openingCommentsSB = new StringBuilder();
        Match commentsMatch = s_OpeningCommentRegex.Match(contents);
        if (commentsMatch.Success)
        {
          Group g = commentsMatch.Groups["Comment"];
          if (g.Success)
            foreach (Capture c in g.Captures)
              openingCommentsSB.AppendLine(c.Value);
          txtDescription.Text = openingCommentsSB.ToString();
        }

        //Sources and sinks use a comment stripped version of the file:
        StringBuilder activeSB = new StringBuilder();
        StringBuilder commentSB = new StringBuilder();
        StringBuilder relevantSB = new StringBuilder();
        for (Match m = s_CommentRemovingRegex.Match(contents, commentsMatch.Index + commentsMatch.Length);
             m.Success; m = m.NextMatch())
        {
          relevantSB.AppendLine(m.Value);
          activeSB.AppendLine(m.Groups["Active"].Value);
          if (m.Groups["Comment"].Success)
            commentSB.AppendLine(m.Groups["Comment"].Value);
          if (m.Groups["Active"].Value.ToLowerInvariant().Trim() == "end")
            break;
          //Now, stopping at the End token:
          if (s_EndRegex.Match(m.Value).Success)
            break;
        }
        string relevant = relevantSB.ToString();
        string commentsRemoved = activeSB.ToString();
        string commentsOnly = commentSB.ToString();
        if (!s_EndRegex.Match(commentsRemoved).Success)
          Log.Message("'End' token not found. Reading to end of file (May cause unpredictable results)", MessageType.Warning);

        if (savedVersion < MinVersion)
        {
          txtDescription.Text += "\r\n---- Upgraded To Reaction Editor Format " + DateTime.Now.Date.ToString("dd/MM/yyyy") + " ----";
          if (!string.IsNullOrEmpty(commentsOnly.Trim()))
            txtDescription.Text += "\r\n\r\n------------ Original Comments ------------\r\n"
                                    + commentsOnly;
        }

        List<int> indexlist = new List<int>();
        int sourceIndex = -1, sinkindex = -1, HXindex = -1;

        //Sources:
        Match sourcesSinksMatch = CompoundListReaction.s_SourceSinkRegex.Match(relevant);
        if (sourcesSinksMatch.Success && sourcesSinksMatch.Groups["Type"].Value.ToLowerInvariant() == "source")
        {
          m_Sources = new CompoundListReaction(sourcesSinksMatch);
          if (!m_Sources.Enabled && savedVersion < MinVersion)
            m_Sources = null;
          else
          {
            sourceIndex = sourcesSinksMatch.Index;
            SetupSources();
            indexlist.Add(sourceIndex);
            sourcesSinksMatch = sourcesSinksMatch.NextMatch();
          }
        }

        //Reactions:
        Match start = s_RxnBlockStartRegex.Match(relevant);
        Match end = s_RxnBlockEndRegex.Match(relevant);
        if (!start.Success || !end.Success)
          throw new Exception("Reaction Block Not Found");

        int rxnBlockStart = start.Index + start.Length;
        int rxnBlockEnd = end.Index;
        string rxnBlock = relevant.Substring(rxnBlockStart, rxnBlockEnd - rxnBlockStart);

        Dictionary<int, SimpleReaction> indices = new Dictionary<int, SimpleReaction>();
        FindReactions(rxnBlock, SimpleReaction.s_GeneralReactionRegex, savedVersion >= MinVersion, ref indices, start.Index);

        //Sinks:
        if (sourcesSinksMatch.Success && sourcesSinksMatch.Groups["Type"].Value.ToLowerInvariant() == "sink")
        {
          m_Sinks = new CompoundListReaction(sourcesSinksMatch);
          if (!m_Sinks.Enabled && savedVersion < MinVersion)
            m_Sinks = null;
          else
          {
            sinkindex = sourcesSinksMatch.Index;
            indexlist.Add(sinkindex);
            SetupSinks();
          }
        }

        //Heat Exchange:
        Match HXMatch = HXReaction.s_HXRegex.Match(relevant);
        if (HXMatch.Success)
        {
          m_HX = new HXReaction(HXMatch);
          if (!m_HX.Enabled && savedVersion < MinVersion)
            m_HX = null;
          else
          {
            HXindex = HXMatch.Index;
            indexlist.Add(HXindex);
            SetupHX();
          }
        }

        //Reaction Editor Saved Comments:
        //First Reactant:
        chkFirstReactant.Checked = contents.ToLowerInvariant().Contains("<usefirstreactant=true>");
        //LastSelected:
        Match LSMatch = s_LastSelectedRegex.Match(contents);
        if (LSMatch.Success)
        {
          int index;
          if (int.TryParse(LSMatch.Groups["Value"].Value, out index) && index < lstReactions.Items.Count) //"None" will return false here, therefore selecting nothing.
            lstReactions.Items[index].Selected = true;
        }
        else if (lstReactions.Items.Count > 0)
          lstReactions.Items[0].Selected = true;

        //To handle reaction numbers:
        indexlist.AddRange(indices.Keys);
        indexlist.Sort();
        int num = 1;
        foreach (int i in indexlist)
        {
          if (indices.ContainsKey(i))
          {
            SimpleReaction currentReaction = indices[i];
            if (currentReaction.Enabled)
              currentReaction.ReactionNumber = currentReaction.OriginalReactionNumber = num++;
            currentReaction.Backup();
            currentReaction.Initialised = true;
          }
          else if (i == sourceIndex && m_Sources.Enabled)
            m_Sources.ReactionNumber = m_Sources.OriginalReactionNumber = num++;
          else if (i == sinkindex && m_Sinks.Enabled)
            m_Sinks.ReactionNumber = m_Sinks.OriginalReactionNumber = num++;
          else if (i == HXindex && m_HX.Enabled)
            m_HX.ReactionNumber = m_HX.OriginalReactionNumber = num++;
        }

        Changed = false;
        if (lstReactions.Items.Count != 1)
          Log.Message("File opened. " + lstReactions.Items.Count + " Reactions found.", MessageType.Note);
        else
          Log.Message("File opened. 1 Reaction found.", MessageType.Note);
        Log.RemoveSource();
      }
      finally
      {
        UpdateReactionNumbers();
        m_bLoading = false;
      }
    }
コード例 #4
0
ファイル: FrmReaction.cs プロジェクト: ChrisMoreton/Test3
 protected void DoAddHX(object sender, EventArgs e)
 {
   m_HX = new HXReaction();
   SetupHX();
   m_HX.LVI.Selected = true;
   comboHXType.Select();
 }