예제 #1
0
 /// <summary>
 /// Attaches a new outgoing stream to the process unit
 /// </summary>
 /// <param name="stream">The stream to attach</param>
 /// <returns>Whether or not the stream was successfully attached</returns>
 public virtual bool AttachOutgoingStream(AbstractStream stream)
 {
     if (CanAcceptOutgoingStream(stream))
     {
         m_outgoingStreams.Add(stream);
         StreamsChanged(this, EventArgs.Empty);
         return(true);
     }
     return(false);
 }
예제 #2
0
        public StreamPropertiesTable(AbstractStream parentStream)
        {
            m_type = (parentStream is HeatStream) ? StreamType.Heat : StreamType.Chemical;

            // Keep a reference to the parent stream
            m_parent = parentStream;

            if (StreamType.Chemical == m_type)
            {
                m_temperature = "TM" + parentStream.Id.ToString();
            }

            // Add a default row for heat streams
            if (StreamType.Heat == m_type)
            {
                AddNewRow();
            }
        }
예제 #3
0
        /// <summary>
        /// Gets whether or not the process unit can accept the specified stream as an outgoing stream
        /// in its current state.
        /// </summary>
        public virtual bool CanAcceptOutgoingStream(AbstractStream stream)
        {
            // We can never accept a single stream as both incoming and outgoing (meaning this
            // process unit would be both the source and destination of the stream), so check
            // for this first.
            if (this == stream.Destination)
            {
                return(false);
            }

            //first, figure out how many units we have
            var result = from c in m_outgoingStreams
                         where c.GetType() == stream.GetType()
                         select c;
            int numResults = result.Count();

            //at this poing I'm breaking down and doing type checking.  I think that there's
            //a way to not check types, but for now, this is what I have to do
            int maxTypes = 0;

            if (stream is HeatStream)
            {
                maxTypes = MaxOutgoingHeatStreams;
            }
            else if (stream is ChemicalStream)
            {
                maxTypes = MaxOutgoingStreams;
            }

            //-1 because -1 means infinity
            if (maxTypes == -1)
            {
                return(true);
            }
            else
            {
                return(maxTypes > numResults);
            }
        }
예제 #4
0
        /// <summary>
        /// Removes a stream from the workspace. Any process units that have this stream in
        /// their list of incoming or outgoing streams will have it removed.
        /// Note that no undo/redo actions are created in this function. If undo/redo actions
        /// are desired, they must be handled elsewhere.
        /// </summary>
        public void RemoveStream(AbstractStream stream)
        {
            foreach (AbstractProcessUnit apu in m_procUnits)
            {
                if (apu.IncomingStreams.Contains(stream))
                {
                    apu.DetachIncomingStream(stream);
                }
                if (apu.OutgoingStreams.Contains(stream))
                {
                    apu.DetachOutgoingStream(stream);
                }
            }

            m_streams.Remove(stream);

            // Invoke the collection change event, if non-null
            if (null != StreamsCollectionChanged)
            {
                StreamsCollectionChanged(this, EventArgs.Empty);
            }
        }
예제 #5
0
        public void AddStream(AbstractStream stream)
        {
            if (null == stream)
            {
                throw new ArgumentNullException(
                          "Cannot add a null stream to a workspace");
            }

            // Make sure that the stream ID is unique. This is very important.
            if (null != GetStream(stream.Id))
            {
                throw new InvalidOperationException(string.Format(
                                                        "A stream with ID={0} already exists in the workspace. The new stream that was " +
                                                        "passed to \"AddAStream\" also had this ID. Each stream in the workspace is required " +
                                                        "to have a unique ID.", stream.Id));
            }

            m_streams.Add(stream);

            if (null != StreamsCollectionChanged)
            {
                StreamsCollectionChanged(this, EventArgs.Empty);
            }
        }
예제 #6
0
 /// <summary>
 /// Dettaches an outgoing stream to the process unit
 /// </summary>
 /// <param name="stream">The stream to dettach</param>
 public virtual void DetachOutgoingStream(AbstractStream stream)
 {
     m_outgoingStreams.Remove(stream);
     StreamsChanged(this, EventArgs.Empty);
 }
예제 #7
0
        public StreamPropertiesTable(XElement loadFromMe, AbstractStream parentStream)
        {
            // Keep a reference to the parent stream
            m_parent = parentStream;

            if (loadFromMe.Name.LocalName.Equals("ChemicalStreamPropertiesWindow"))
            {
                // Set the type
                m_type = StreamType.Chemical;

                // Load the data rows
                XElement dataRowsEl = loadFromMe.Element("DataRows");
                if (null == dataRowsEl)
                {
                    throw new Exception("Chemical stream properties XML is missing \"DataRows\" element.");
                }

                // Load each <ChemicalStreamData>
                foreach (XElement csdEl in dataRowsEl.Elements("ChemicalStreamData"))
                {
                    AddRow(new ChemicalStreamData(csdEl));
                }

                // Load the location
                XElement locEl = loadFromMe.Element("Location");
                m_location.X = Convert.ToDouble(locEl.Element("X").Value);
                m_location.Y = Convert.ToDouble(locEl.Element("Y").Value);

                // Look for <Temperature> node
                XElement temperatureEl = loadFromMe.Element("Temperature");
                if (null != temperatureEl)
                {
                    m_temperature      = temperatureEl.Element("Quantity").Value;
                    m_temperatureUnits = Convert.ToInt32(temperatureEl.Element("Units").Value);

                    // Look for "UserHasChangedTemperature" element. This property was added in
                    // August 2012 which is after several professors had been working with
                    // ChemProV files. So in older files this element is not likely to be present.
                    XElement userChangedEl = temperatureEl.Element("UserHasChangedTemperature");
                    if (null != userChangedEl)
                    {
                        if (!bool.TryParse(userChangedEl.Value, out m_userHasChangedTemperature))
                        {
                            // Default to false if the parse fails
                            m_userHasChangedTemperature = false;
                        }
                    }
                }
            }
            else if (loadFromMe.Name.LocalName.Equals("HeatStreamPropertiesWindow"))
            {
                // Set the type
                m_type = StreamType.Heat;

                // Load the data rows
                XElement dataRowsEl = loadFromMe.Element("DataRows");
                if (null == dataRowsEl)
                {
                    throw new Exception("Chemical stream properties XML is missing \"DataRows\" element.");
                }

                // Load each <HeatStreamData>
                foreach (XElement hsdEl in dataRowsEl.Elements("HeatStreamData"))
                {
                    AddRow(new HeatStreamData(hsdEl));
                }

                // Load the location
                XElement locEl = loadFromMe.Element("Location");
                m_location.X = Convert.ToDouble(locEl.Element("X").Value);
                m_location.Y = Convert.ToDouble(locEl.Element("Y").Value);
            }
            else
            {
                throw new Exception("Unknown stream property table element: " + loadFromMe.Name);
            }
        }
예제 #8
0
        public void Load(XDocument doc)
        {
            // Start by clearing
            Clear();

            string setting = doc.Element("ProcessFlowDiagram").Attribute("DifficultySetting").Value;

            TrySetDifficulty((OptionDifficultySetting)Enum.Parse(typeof(OptionDifficultySetting), setting, true));

            // Load process units. We have to do this before the streams because the stream loading
            // does the attaching to the process units.
            XElement processUnits = doc.Descendants("ProcessUnits").ElementAt(0);

            foreach (XElement xmPU in processUnits.Elements())
            {
                m_procUnits.Add(ProcessUnitFactory.Create(xmPU));
            }

            // Load streams (constructors attach process units)
            XElement streamList = doc.Descendants("Streams").ElementAt(0);

            foreach (XElement streamElement in streamList.Elements())
            {
                // Check the type so we know what to create
                string unitType = (string)streamElement.Attribute("StreamType");

                if ("Chemical" == unitType)
                {
                    m_streams.Add(new ChemicalStream(streamElement, m_procUnits));
                }
                else
                {
                    m_streams.Add(new HeatStream(streamElement, m_procUnits));
                }

                // Remember that the properties tables are not stored within the
                // stream element and get loaded later
            }

            // Now that the streams are loaded, we can load the properties windows
            XElement tablesList = doc.Descendants("PropertiesWindows").ElementAt(0);

            foreach (XElement table in tablesList.Elements())
            {
                // Get the table's target
                string parentName = (string)table.Element("ParentStream");

                // Create the properties table
                AbstractStream parentStream = GetStream(Convert.ToInt32(parentName.Split('_')[1]));
                parentStream.PropertiesTable = new StreamPropertiesTable(table, parentStream);
            }

            // Load equations
            XElement equations = doc.Descendants("Equations").ElementAt(0);

            foreach (XElement xmlEquation in equations.Elements())
            {
                EquationModel rowModel = EquationModel.FromXml(xmlEquation);
                m_equations.Add(rowModel);
            }

            // Load the sticky notes
            XElement stickyNoteList = doc.Descendants("StickyNotes").ElementAt(0);

            foreach (XElement note in stickyNoteList.Elements())
            {
                m_stickyNotes.Add(new Logic.StickyNote(note, null));
            }

            // Check for degrees of freedom analysis
            XElement df = doc.Element("ProcessFlowDiagram").Element("DegreesOfFreedomAnalysis");

            if (null != df)
            {
                m_dfAnalysis.Text = df.Element("Text").Value;

                foreach (XElement el in df.Elements("Comment"))
                {
                    string     userName = string.Empty;
                    XAttribute userAttr = el.Attribute("UserName");
                    if (null != userAttr)
                    {
                        userName = userAttr.Value;
                    }
                    m_dfAnalysis.Comments.Add(new BasicComment(el.Value, userName));
                }
            }
            else
            {
                m_dfAnalysis.Text = string.Empty;
            }

            // Fire events
            StreamsCollectionChanged(this, EventArgs.Empty);
            ProcessUnitsCollectionChanged(this, EventArgs.Empty);
        }