Пример #1
0
        /**
         * Returns the double Profile matching the key given. If no Profile is found, it goes back one Event
         * and checks again until it gets to the initial state.
         * @param key The double state variable key that is being looked up.
         * @return The Profile saved in the state.
         */
        public HSFProfile <double> getProfile(StateVarKey <double> key)
        {
            HSFProfile <double> valueOut;

            if (Ddata.Count != 0)                         // Are there any Profiles in there?
            {
                if (Ddata.TryGetValue(key, out valueOut)) //see if our key is in there
                {
                    return(valueOut);
                }
            }
            return(Previous.getProfile(key));        // This isn't the right profile, go back one and try it out!
        }
Пример #2
0
        /**
         * Adds a double Profile to the state with the given key. If no Profile exists, a new Profile is created
         * with the corresponding key. If a Profile exists with that key, the Profile is appended onto the end of the Profile.
         * @param key The key corresponding to the state variable.
         * @param profIn The Profile to be added to the double Profile.
         */
        public void addValue(StateVarKey <double> key, HSFProfile <double> profIn)
        {
            HSFProfile <double> valueOut;

            if (!Ddata.TryGetValue(key, out valueOut)) // If there's no Profile matching that key, insert a new one.
            {
                Ddata.Add(key, profIn);
            }
            else         // Otherwise, add this data point to the existing Profile.
            {
                valueOut.Add(profIn);
            }
        }
Пример #3
0
        /**
         * Gets the double value of the state at a certain time. If the exact time is not found, the data is
         * assumed to be on a zero-order hold, and the last value set is found.
         * @param key The double state variable key that is being looked up.
         * @param time The time the value is looked up at.
         * @return A pair containing the last time the variable was set, and the double value.
         */
        public KeyValuePair <double, double> getValueAtTime(StateVarKey <double> key, double time)
        {
            HSFProfile <double> valueOut;

            if (Ddata.Count != 0)                         // Are there any Profiles in there?
            {
                if (Ddata.TryGetValue(key, out valueOut)) //see if our key is in there
                {
                    return(valueOut.DataAtTime(time));
                }
            }
            return(Previous.getValueAtTime(key, time));         //either no profiles or none that match our keys, try finding it in the previous one
        }
Пример #4
0
        /*
         * Gets the last double value set for the given state variable key in the state. If no value is found
         * it checks the previous state, continuing all the way to the initial state.
         * @param key The double state variable key that is being looked up.
         * @return A pair containing the last time the variable was set, and the double value.
         */
        public KeyValuePair <double, double> getLastValue(StateVarKey <double> key)
        {
            HSFProfile <double> valueOut;

            if (Ddata.Count != 0)                         // Are there any Profiles in there?
            {
                if (Ddata.TryGetValue(key, out valueOut)) //see if our key is in there
                {
                    return(valueOut.Last());              //found it, return it TODO: return last value or pair?
                }
            }
            return(Previous.getLastValue(key)); //either no profiles or none that match our keys, try finding it in the previous one
        }
Пример #5
0
        /**
         * Adds a double Profile value pair to the state with the given key. If no Profile exists, a new Profile is created
         * with the corresponding key. If a Profile exists with that key, the pair is appended onto the end of the Profile.
         * Ensure that the Profile is still time ordered if this is the case.
         * @param key The key corresponding to the state variable.
         * @param pairIn The pair to be added to the integer Profile.
         */
        public void addValue(StateVarKey <double> key, KeyValuePair <double, double> pairIn)
        {
            HSFProfile <double> valueIn = new HSFProfile <double>(pairIn);
            HSFProfile <double> valueOut;

            if (!Ddata.TryGetValue(key, out valueOut)) // If there's no Profile matching that key, insert a new one.
            {
                Ddata.Add(key, valueIn);
            }
            else                      // Otherwise, add this data point to the existing Profile.
            {
                valueOut.Add(pairIn); //TODO: make sure this is ok. was formally iterator.second.data
            }
        }
Пример #6
0
        /**
         * Sets the double Profile in the state with its matching key. If a Profile is found already under
         * that key, this will overwrite the old Profile.
         * @param key The double state variable key that is being set.\
         * @param profIn The double Profile being saved.
         */
        public void setProfile(StateVarKey <double> key, HSFProfile <double> profIn)
        {
            HSFProfile <double> valueOut;

            if (!Ddata.TryGetValue(key, out valueOut)) // If there's no Profile matching that key, insert a new one.
            {
                Ddata.Add(key, profIn);
            }
            else           // Otherwise, erase whatever is there, and insert a new one.
            {
                Ddata.Remove(key);
                Ddata.Add(key, profIn);
            }
        }
Пример #7
0
        /** TODO: make sure valueOut is a good replacement for iterator.second
         * Returns the double Profile for this state and all previous states merged into one Profile
         * @param key The double state variable key that is being looked up.
         * @return The full Profile
         */
        public HSFProfile <double> getFullProfile(StateVarKey <double> key)
        {
            HSFProfile <double> valueOut = new HSFProfile <double>();

            if (Ddata.Count != 0)                         // Are there any Profiles in there?
            {
                if (Ddata.TryGetValue(key, out valueOut)) //see if our key is in there
                {
                    if (Previous != null)                 // Check whether we are at the first state
                    {
                        return(HSFProfile <double> .MergeProfiles(valueOut, Previous.getFullProfile(key)));
                    }
                    return(valueOut);
                }
            }
            if (Previous != null)
            {
                return(Previous.getFullProfile(key)); // If no data, return profile from previous states
            }
            return(valueOut);                         //return empty profile
        }
Пример #8
0
 private void textData(int i)
 {
     try
     {
         if (this.label1.InvokeRequired)
         {
             Ddata d = new Ddata(textData);
             this.Invoke(d, new object[] { i });
         }
         else
         {
             if (i == 1)
             {
                 label1.BackColor = Color.Green;
                 timer1.Start();
             }
             else
             {
                 label1.BackColor = Color.Red;
             }
         }
     }
     catch { }
 }
Пример #9
0
 /// <summary>
 /// Returns the integer Profile matching the key given. If no Profile is found, it goes back one Event
 /// and checks again until it gets to the initial state.
 /// </summary>
 /// <typeparam name="T">The type of the profile we are getting</typeparam>
 /// <param name="_key">The state variable key that is being looked up.</param>
 /// <returns>Profile saved in the state.</returns>
 public HSFProfile <T> GetProfile <T>(StateVarKey <T> _key)
 {
     if (_key.GetType() == typeof(StateVarKey <int>))
     {
         HSFProfile <int> valueOut;
         if (Idata.Count != 0)
         {                                              // Are there any Profiles in there?
             if (Idata.TryGetValue(_key, out valueOut)) //see if our key is in there
             {
                 return((dynamic)valueOut);
             }
         }
         return(Previous.GetProfile(_key)); // This isn't the right profile, go back one and try it out!
     }
     else if (_key.GetType() == typeof(StateVarKey <double>))
     {
         HSFProfile <double> valueOut;
         if (Ddata.Count != 0)
         {                                              // Are there any Profiles in there?
             if (Ddata.TryGetValue(_key, out valueOut)) //see if our key is in there
             {
                 return((dynamic)valueOut);
             }
         }
         return(Previous.GetProfile(_key)); // This isn't the right profile, go back one and try it out!
     }
     else if (_key.GetType() == typeof(StateVarKey <bool>))
     {
         HSFProfile <bool> valueOut;
         if (Ddata.Count != 0)
         {                                              // Are there any Profiles in there?
             if (Bdata.TryGetValue(_key, out valueOut)) //see if our key is in there
             {
                 return((dynamic)valueOut);
             }
         }
         return(Previous.GetProfile(_key)); // This isn't the right profile, go back one and try it out!
     }
     else if (_key.GetType() == typeof(StateVarKey <Matrix <double> >))
     {
         HSFProfile <Matrix <double> > valueOut;
         if (Ddata.Count != 0)
         {                                              // Are there any Profiles in there?
             if (Mdata.TryGetValue(_key, out valueOut)) //see if our key is in there
             {
                 return((dynamic)valueOut);
             }
         }
         return(Previous.GetProfile(_key)); // This isn't the right profile, go back one and try it out!
     }
     else if (_key.GetType() == typeof(StateVarKey <Quat>))
     {
         HSFProfile <Quat> valueOut;
         if (Ddata.Count != 0)
         {                                              // Are there any Profiles in there?
             if (Qdata.TryGetValue(_key, out valueOut)) //see if our key is in there
             {
                 return((dynamic)valueOut);
             }
         }
         return(Previous.GetProfile(_key)); // This isn't the right profile, go back one and try it out!
     }
     throw new ArgumentException("Profile Type Not Found");
 }