Exemplo n.º 1
0
        public void TestMoleUnitChange()
        {
            MainPage  mp1 = new MainPage();
            Workspace w   = mp1.GetLogicalWorkspace();

            // Add a new stream with a table to the workspace
            ChemicalStream cs1 = new ChemicalStream(1);

            cs1.PropertiesTable = new StreamPropertiesTable(cs1);
            w.AddStream(cs1);

            // The DrawingCanvas control should have added a stream control
            ChemProV.PFD.Streams.StreamControl streamControl =
                mp1.WorkspaceReference.DrawingCanvasReference.GetStreamControl(cs1);
            Assert.IsNotNull(streamControl, "DrawingCanvas control did not correctly create a " +
                             "stream control for a stream that was added to the workspace.");

            // From the stream control we can get the properties window control
            UI.StreamTableControl props = streamControl.Table;
            Assert.IsNotNull(props, "Stream control had a null table control.");

            // Add a default data row with label "M1" if it's not already there
            if (0 == cs1.PropertiesTable.RowCount)
            {
                ChemicalStreamData csd = cs1.PropertiesTable.AddNewRow() as ChemicalStreamData;
                csd.SelectedCompound = "Overall";
                csd.Label            = "M1";
                csd.UserHasRenamed   = false;
            }

            // Find the text box in the properties window with the text "M1"
            TextBox tbLabel = props.GetControl(cs1.PropertiesTable.Rows[0], "Label") as TextBox;

            Assert.IsNotNull(tbLabel, "Could not find text box for row label. If the code has changed " +
                             "such that there is no longer a default row in chemical streams tables or the default " +
                             "row has different units, then this test needs to be altered.");
            Assert.IsTrue(tbLabel.Text.Equals("M1"), "Default label was not M1");

            // Find the combo box for the units
            ComboBox cbUnits = props.GetControl(cs1.PropertiesTable.Rows[0], "SelectedUnits") as ComboBox;

            Assert.IsNotNull(cbUnits, "Could not find combo box control for selected units");

            // Select mole %, which should change the label from M1 to N1
            cbUnits.SelectedItem = "mol %";

            // Verify that the label changed to "N1"
            Assert.IsTrue(tbLabel.Text.Equals("N1"), "Test Failed: After unit change, the label " +
                          "did not change from M1 to N1");

            // What would be nice to add to this test in the future:
            // Change the text in tbLabel which simulates the user manually renaming the row. Change it to
            // something like "nn1". Then change the units again to something like fractions, which would
            // normally change 'n' to 'x', but shouldn't after a manual rename.
        }
Exemplo n.º 2
0
 /// <summary>
 /// This is called whenever ChemicalStreamData in an exisiting table is changed
 /// </summary>
 /// <param name="itable">This is the table who's data was changed</param>
 public void DataChanged(DataUpdatedEventArgs changedData, ChemicalStreamData data, IPropertiesTable itable)
 {
     if (changedData.OldData as string != null && (changedData.OldData as string) != "")
     {
         tableEntries.Remove(changedData.OldData as string);
         tableEntries.Add(data.Label, data);
     }
     else
     {
         tableEntries.Remove(data.Label);
         tableEntries.Add(data.Label, data);
     }
     TableDataChanged(itable, new EventArgs());
 }
Exemplo n.º 3
0
        private void AutoLabel(ChemicalStreamData row)
        {
            // Start by getting the character for the units
            char startChar;

            if ("massFrac" == row.SelectedUnits)
            {
                // We use 'X' and 'x' for mass fraction
                startChar = 'X';
            }
            else if ("molFrac" == row.SelectedUnits)
            {
                // Y,y for mole fraction
                startChar = 'Y';
            }
            else if ("mol %" == row.SelectedUnits || "mol" == row.SelectedUnits ||
                     "mol/sec" == row.SelectedUnits)
            {
                // N,n for anything remaining that has moles
                startChar = 'N';
            }
            else
            {
                // M,m for everything else
                startChar = 'M';
            }

            // Determine the row number
            int rowNum = m_table.IndexOfRow(row);

            // Now set the actual label
            if ("Overall" == row.SelectedCompound)
            {
                // Label of the form: "[startChar.Upper][streamNum]"
                row.Label = startChar.ToString() + m_table.Stream.Id.ToString();
            }
            else if (string.IsNullOrEmpty(row.SelectedCompound))
            {
                // Label of the form: "[startChar.Lower][streamNum][rowIndex + 1]"
                row.Label = char.ToLower(startChar).ToString() + m_table.Stream.Id.ToString() + (rowNum + 1).ToString();
            }
            else
            {
                // Label of the form: "[startChar.Lower][streamNum][twoCharCompound]
                PFD.Streams.PropertiesWindow.Compound compound =
                    PFD.Streams.PropertiesWindow.CompoundFactory.GetElementsOfCompound(
                        row.SelectedCompound.ToLower());
                row.Label = char.ToLower(startChar).ToString() + m_table.Stream.Id.ToString() + compound.Abbr;
            }
        }
Exemplo n.º 4
0
        private void ComboBoxField_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Get the column index for the control.Remember that there's an extra column in the
            // grid (with respect to the data row) for the row removal buttons.
            int column = (int)(sender as ComboBox).GetValue(Grid.ColumnProperty) - 1;

            Tuple <IStreamDataRow, string> info = (sender as ComboBox).Tag as
                                                  Tuple <IStreamDataRow, string>;

            if (null != info)
            {
                string newValue = (sender as ComboBox).SelectedItem as string;
                if (null == newValue)
                {
                    newValue = (sender as ComboBox).SelectedItem.ToString();
                }

                // Set the new value
                m_ignoreRowPropertyChanges = true;
                info.Item1[column]         = newValue;
                m_ignoreRowPropertyChanges = false;

                // If we just changed the "SelectedUnits" field, then check if we have to auto-
                // rename the row
                ChemicalStreamData csd = info.Item1 as ChemicalStreamData;
                if ((info.Item2.Equals("SelectedUnits") || info.Item2.Equals("SelectedCompound")) &&
                    !info.Item1.UserHasRenamed && null != csd)
                {
                    m_programmaticallyChanging = true;

                    // Remove the event handler for the label text box while we change the label
                    TextBox tbLabel = GetControl(info.Item1, "Label") as TextBox;
                    tbLabel.TextChanged -= this.TextField_TextChanged;

                    // Change the label in the data structure
                    AutoLabel(csd);

                    // Re-subscribe to the label text box changes
                    tbLabel.TextChanged += this.TextField_TextChanged;

                    m_programmaticallyChanging = false;
                    csd.UserHasRenamed         = false;
                }
            }
        }