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
        private void WorkspaceStreamsCollectionChanged(object sender, EventArgs e)
        {
            // Start by unsubscribing from the old list
            foreach (StreamPropertiesTable table in m_monitoredTables)
            {
                table.RowPropertyChanged -= this.TableRowPropertyChanged;
            }

            // Rebuild the list and subsribe to changes in chemical stream property tables
            m_monitoredTables.Clear();
            foreach (AbstractStream stream in m_workspace.Streams)
            {
                ChemicalStream cs = stream as ChemicalStream;
                if (null == cs)
                {
                    // Ignore it if it's not a chemical stream
                    continue;
                }

                StreamPropertiesTable table = cs.PropertiesTable;
                if (null == table)
                {
                    throw new InvalidOperationException(
                              "Stream in workspace has a null table");
                }
                m_monitoredTables.Add(table);
                table.RowPropertyChanged += this.TableRowPropertyChanged;
            }

            //this code handles changes made to streams for the purposes of the scopes menu
            foreach (AbstractStream stream in m_monitoredStreams)
            {
                stream.PropertyChanged -= this.StreamPropertyChanged;
            }
            m_monitoredStreams.Clear();
            foreach (AbstractStream stream in m_workspace.Streams)
            {
                m_monitoredStreams.Add(stream);
                stream.PropertyChanged += new PropertyChangedEventHandler(StreamPropertyChanged);
            }
            UpdateCompounds();
            updateScopes();
        }
Exemplo n.º 3
0
        private static List <string> GetTypeOptions(Workspace workspace, IStreamDataRow excludeMe)
        {
            // Start by making a list of unique selected compounds from all rows in all stream tables,
            // except for the one we need to exclude.
            List <string> compounds = new List <string>();

            foreach (AbstractStream stream in workspace.Streams)
            {
                ChemicalStream cs = stream as ChemicalStream;
                if (null != cs)
                {
                    // Go through all the rows in the properties table
                    foreach (IStreamDataRow otherRow in cs.PropertiesTable.Rows)
                    {
                        // Skip the row if it's the one we need to exclude
                        if (object.ReferenceEquals(otherRow, excludeMe))
                        {
                            continue;
                        }

                        string selectedCompound = (otherRow as ChemicalStreamData).SelectedCompound;
                        if (!string.IsNullOrEmpty(selectedCompound) &&
                            !compounds.Contains(selectedCompound))
                        {
                            compounds.Add(selectedCompound);
                        }
                    }
                }
            }

            // Now build a list of elements for the compounds in the list
            List <string> elements = new List <string>();

            foreach (string compoundstr in compounds)
            {
                Compound compound = CompoundFactory.GetElementsOfCompound((compoundstr).ToLower());

                foreach (KeyValuePair <Element, int> element in compound.elements)
                {
                    if (!elements.Contains(element.Key.Name))
                    {
                        elements.Add(element.Key.Name);
                    }
                }
            }

            List <string> equationTypes = new List <string>();

            equationTypes.Add("Total");
            equationTypes.Add("Specification");
            equationTypes.Add("Basis");
            foreach (string compound in compounds)
            {
                if (compound != "Overall")
                {
                    equationTypes.Add((new EquationType(EquationTypeClassification.Compound, compound)).ToString());
                }
            }
            if (workspace.Difficulty != OptionDifficultySetting.MaterialBalance)
            {
                foreach (string element in elements)
                {
                    equationTypes.Add((new EquationType(EquationTypeClassification.Atom, element + "(e)")).ToString());
                }
            }

            return(equationTypes);
        }
Exemplo n.º 4
0
        public void TestSaveLoad()
        {
            int       i;
            Workspace ws1  = new Workspace();
            Random    rand = new Random();

            // Add a random number of process units
            List <int> puIDs = new List <int>();
            int        numPU = rand.Next(25);

            for (i = 0; i < numPU; i++)
            {
                AbstractProcessUnit pu = new Mixer();
                ws1.AddProcessUnit(pu);
                puIDs.Add(pu.Id);
            }

            // Add a random number of chemical streams
            int numStreams = rand.Next(10);

            for (i = 0; i < numStreams; i++)
            {
                AbstractStream stream = new ChemicalStream(AbstractStream.GetNextUID());
                ws1.AddStream(stream);

                // Don't forget that the properties table needs to be created separately
                stream.PropertiesTable = new StreamPropertiesTable(stream);

                // 50% chance of connecting a destination (attempting a connect that is)
                if (0 == (rand.Next() % 2))
                {
                    AbstractProcessUnit pu = ws1.ProcessUnits[rand.Next(ws1.ProcessUnitCount)];
                    if (pu.AttachIncomingStream(stream))
                    {
                        stream.Destination = pu;
                    }
                }
            }

            // Save the workspace to a memory stream
            MemoryStream ms = new MemoryStream();

            ws1.Save(ms, "TEST_VersionNA");

            // Load to a new workspace
            Workspace ws2 = new Workspace();

            ws2.Load(ms);

            // Make sure the number of process units and streams match
            Assert.IsTrue(numPU == ws2.ProcessUnitCount,
                          "Number of process units between saved document (" + numPU.ToString() +
                          ") and loaded document (" + ws2.ProcessUnitCount.ToString() + ") do not match");
            Assert.IsTrue(numStreams == ws2.Streams.Count,
                          "Number of streams between saved document (" + numStreams.ToString() +
                          ") and loaded document (" + ws2.Streams.Count.ToString() + ") do not match");

            // Test that the incoming/outgoing streams for process units match
            foreach (AbstractProcessUnit pu1 in ws1.ProcessUnits)
            {
                AbstractProcessUnit pu2 = ws2.GetProcessUnit(pu1.Id);
                Assert.IsNotNull(pu2,
                                 "Process unit with ID=" + pu1.Id.ToString() + " from workspace 1 (saved) was not " +
                                 "found in workspace 2 (loaded).");

                // For now just compare outoging stream count
                Assert.IsTrue(pu1.OutgoingStreamCount == pu2.OutgoingStreamCount,
                              "Mis-match outgoing stream count");
            }
        }