Exemple #1
0
        public void AddExample(Gesture p)
        {
            bool success = true;
            try
            {
                // first, ensure that p's name is right
                string name = ParseName(p.Name);
                if (name != _name)
                    throw new ArgumentException("Prototype name does not equal the name of the category to which it was added.");

                // second, ensure that it doesn't already exist
                for (int i = 0; i < _prototypes.Count; i++)
                {
                    Gesture p0 = (Gesture) _prototypes[i];
                    if (p0.Name == p.Name)
                        throw new ArgumentException("Prototype name was added more than once to its category.");
                }
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                success = false;
            }
            if (success)
            {
                _prototypes.Add(p);
            }
        }
		public bool SaveGesture(string filename, ArrayList points)
		{
			// add the new prototype with the name extracted from the filename.
            string name = Gesture.ParseName(filename);
            if (_gestures.ContainsKey(name))
                _gestures.Remove(name);
			Gesture newPrototype = new Gesture(name, points);
            _gestures.Add(name, newPrototype);

            // figure out the duration of the gesture
            PointR p0 = (PointR) points[0];
            PointR pn = (PointR) points[points.Count - 1];

			// do the xml writing
			bool success = true;
			XmlTextWriter writer = null;
			try
			{
				// save the prototype as an Xml file
				writer = new XmlTextWriter(filename, Encoding.UTF8);
				writer.Formatting = Formatting.Indented;
				writer.WriteStartDocument(true);
				writer.WriteStartElement("Gesture");
				writer.WriteAttributeString("Name", name);
				writer.WriteAttributeString("NumPts", XmlConvert.ToString(points.Count));
                writer.WriteAttributeString("Millseconds", XmlConvert.ToString(pn.T - p0.T));
                writer.WriteAttributeString("AppName", Assembly.GetExecutingAssembly().GetName().Name);
				writer.WriteAttributeString("AppVer", Assembly.GetExecutingAssembly().GetName().Version.ToString());
				writer.WriteAttributeString("Date", DateTime.Now.ToLongDateString());
				writer.WriteAttributeString("TimeOfDay", DateTime.Now.ToLongTimeString());

				// write out the raw individual points
				foreach (PointR p in points)
				{
					writer.WriteStartElement("Point");
					writer.WriteAttributeString("X", XmlConvert.ToString(p.X));
					writer.WriteAttributeString("Y", XmlConvert.ToString(p.Y));
                    writer.WriteAttributeString("T", XmlConvert.ToString(p.T));
					writer.WriteEndElement(); // <Point />
				}

				writer.WriteEndDocument(); // </Gesture>
			}
			catch (XmlException xex)
			{
				Console.Write(xex.Message);
				success = false;
			}
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                success = false;
            }
			finally
			{
				if (writer != null)
					writer.Close();
			}
			return success; // Xml file successfully written (or not)
		}
 public Category(string name, Gesture firstExample)
 {
     _name = name;
     _prototypes = new ArrayList();
     AddExample(firstExample);
 }
Exemple #4
0
 public Category(string name, Gesture firstExample)
 {
     _name       = name;
     _prototypes = new ArrayList();
     AddExample(firstExample);
 }
Exemple #5
0
 public Category(string name, Gesture firstExample)
 {
     _name       = name;
     _prototypes = new ArrayList();//初始化 ArrayList 类的新实例,该实例为空并且具有默认初始容量
     AddExample(firstExample);
 }