Esempio n. 1
0
		public virtual bool Validate (Beagle.Hit hit)
		{
			if (flavors.Count < 1)
				return false;

			Weight = 0;

			HitFlavor best = null;

			foreach (HitFlavor flavor in flavors) {
				if (! flavor.IsMatch (hit))
					continue;

				if (best == null) {
					best = flavor;
					continue;
				}

				if (flavor.Weight > best.Weight) {
					best = flavor;
				}
			}

			if (best != null) {
				Weight += best.Weight;
				return true;
			}

			return false;
		}
Esempio n. 2
0
        private void connectButton_Click(object sender, RoutedEventArgs e)
        {
            string host           = hostTextBox.Text;
            int    i2cCommandPort = int.Parse(i2cCommandPortTextBox.Text);
            int    cameraPort     = int.Parse(cameraPortTextBox.Text);

            Settings.Default.Host         = host;
            Settings.Default.I2CProxyPort = i2cCommandPort;
            Settings.Default.CameraPort   = cameraPort;
            Settings.Default.Save();

            var robot = new Beagle();

            robot.Host           = host;
            robot.I2CCommandPort = i2cCommandPort;
            robot.I2CPollPort    = i2cCommandPort + 1;
            robot.CameraPort     = cameraPort;
            robot.Init();
            bool ok = robot.Connect();

            if (!ok)
            {
                MessageBox.Show("Unable to connect. Please check your settings.", "Connect", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var main = new MainWindow();

            main.Robot = robot;
            main.Show();

            expectedToClose = true;
            Close();
        }
Esempio n. 3
0
		public RSSFeed (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Group = TileGroup.Feed;

			Title = Hit ["dc:title"];
			Description = Hit ["dc:publisher"];
		}
Esempio n. 4
0
			public ThumbnailRequest (Gtk.Image image, string thumbnail_file, Beagle.Hit hit, int size)
			{
				Image = image;
				ThumbnailFile = thumbnail_file;
				Hit = hit;
				Size = size;
			}
Esempio n. 5
0
		public IMLog (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Group = TileGroup.Conversations;

			Subject.LabelProp = Catalog.GetString ("IM Conversation");

			string alias = hit.GetFirstProperty ("fixme:speakingto_alias");
			string name = hit.GetFirstProperty ("fixme:speakingto");

			if (alias != null && alias != "")
				From.LabelProp = "<b>" + alias + "</b>";
			else if (name != null && name != "")
				From.LabelProp = "<b>" + name + "</b>";
			else
				From.LabelProp = "(unknown)";

			try {
				string starttime = hit.GetFirstProperty ("fixme:starttime");
				
				if (!String.IsNullOrEmpty (starttime))
				    Timestamp = StringFu.StringToDateTime (starttime);
				    
				Date.LabelProp = Utils.NiceShortDate (Timestamp);
			} catch {}
		}
Esempio n. 6
0
		public override Tile BuildTile (Beagle.Hit hit, Beagle.Query query)
		{
			if (ditem == IntPtr.Zero)
				return null;

			if (hit ["fixme:NoDisplay"] == "true")
				return null;

			string notshow = gnome_desktop_item_get_string (ditem, "NotShowIn");
			if (notshow != null && notshow.IndexOf ("GNOME") != -1)
				return null;

			string onlyshow = gnome_desktop_item_get_string (ditem, "OnlyShowIn");
			if (onlyshow != null && onlyshow.IndexOf ("GNOME") == -1)
				return null;


			if (!checked_gconf)
				CheckLockdown();

			if (disable_command_line) {
				string[] categories = hit.GetProperties ("fixme:Categories");

				if (categories != null && Array.IndexOf (categories, "TerminalEmulator") != -1)
					return null;
			}

			return new Application (hit, query, ditem);
		}
Esempio n. 7
0
        static void Main(string[] args)
        {
            var context = Beagle.CreateContext <MyDatabase>(new SqliteEngine("Filename=./test3.db"));

            Debug.WriteLine(context.Store.People == null);
            context.Store.People.Add(new Person()
            {
                Name = "Dylan"
            });
            context.Store.Friends.Add(new Friend()
            {
                FriendName = "Dylan", Name = "Brad"
            });
            context.Store.Friends.Add(new Friend()
            {
                FriendName = "Dylan", Name = "Jacob"
            });
            foreach (var person in context.Store.People)
            {
                Console.WriteLine("[Person] Name=" + person.Name);
            }
            foreach (var f in context.Store.Friends)
            {
                Console.WriteLine("[Friend] Name=" + f.Name, ",FriendName=" + f.Name);
            }

            Console.ReadLine();
        }
Esempio n. 8
0
		        public Hit (uint id, Beagle.Hit hit, string[] fields, Query query)
			{
				this.id = id;
				bHit = hit;
				hitValue = new object[fields.Length];
				int i = 0;

				uri = hit.Uri;

				foreach (string field in fields) {
					// We add String.Empty to attributes because they may be null and we cannot
					// return null objects over DBus
					string[] bfields = Ontologies.XesamToBeagleField (field);

					switch (bfields [0]) {
					case "uri":
						hitValue [i++] = hit.Uri.ToString ();
						break;

					case "mimetype":
						hitValue [i++] = hit.MimeType + String.Empty;
						break;

					case "date":
						hitValue [i++] = hit.Timestamp.ToString ("s");
						break;

					case "snippet":
						SnippetRequest sreq = new SnippetRequest (query, hit);
						SnippetResponse sresp = (SnippetResponse) sreq.Send ();
						hitValue [i++] = sresp.Snippet != null ? sresp.Snippet : String.Empty;
						break;
					    
					default:
						// FIXME: This *will* break since we don't know what the expected
						// type here is, and we're always using strings
						
						List<string> values = new List<string> ();

						foreach (string bfield in bfields) {
							string[] prop = hit.GetProperties (bfield);

							if (prop != null)
								values.AddRange (prop);
						}

						if (values.Count == 0)
							// No values found
							hitValue [i++] = String.Empty;
						else if (values.Count == 1)
							// Only one value -- return as string
							hitValue [i++] = values [0];
						else
							// Multiple values -- returns as string[]
							hitValue [i++] = values.ToArray ();

						break;
					}
				}
			}
Esempio n. 9
0
        public void BeagleBarkTest()
        {
            Beagle beagle = new Beagle();
            bool hunter = beagle.IsHunter.Equals("I was bred to hunt");

            Assert.True(hunter);
        }
Esempio n. 10
0
 public override void Bind(Beagle robot, Joystick joystick)
 {
     base.Bind(robot, joystick);
     if (Joystick != null)
     {
         joystick.PointOfViewPressed += joystick_PointOfViewChanged;
     }
     DataContext = robot.ServoController;
 }
Esempio n. 11
0
		public Task (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Group = TileGroup.Calendar;

			Title = hit.GetFirstProperty ("fixme:summary");

			if (!String.IsNullOrEmpty (hit.GetFirstProperty ("fixme:description")))
				Description = Utils.TrimFirstLine (hit.GetFirstProperty ("fixme:description"));
		}
Esempio n. 12
0
		public Presentation (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Group = TileGroup.Documents;

			if (Hit ["fixme:slide-count"] != null) {
				int count = Int32.Parse (Hit ["fixme:slide-count"]);
				Description = String.Format (Catalog.GetPluralString ("{0} slide", "{0} slides", count), count);
			}
		}
Esempio n. 13
0
		public Contact (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Group = TileGroup.Contact;

			Title = hit.GetFirstProperty ("fixme:Name");
			Description = hit.GetFirstProperty ("fixme:Email");

			if (Hit.GetFirstProperty ("fixme:Email") != null)
				AddAction (new TileAction (Catalog.GetString ("Send Mail"), SendMail));
		}
Esempio n. 14
0
		protected static string GetTitle (Beagle.Hit hit)
		{
			string title;

			title = hit.GetFirstProperty ("dc:title");

			if (String.IsNullOrEmpty (title))
				title = hit.GetFirstProperty ("beagle:ExactFilename");

			return title;
		}
Esempio n. 15
0
		public Docbook (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			if (! String.IsNullOrEmpty (hit.GetFirstProperty ("dc:title")))
				Title = hit.GetFirstProperty ("dc:title");
			else
				Title = hit.GetFirstProperty ("beagle:ExactFilename");

			if (hit ["beagle:IsChild"] == "true")
				Description = hit.GetFirstProperty ("parent:beagle:Filename");
			else
				Description = hit.GetFirstProperty ("beagle:Filename");
		}
Esempio n. 16
0
		private static string GetAddress (Beagle.Hit hit)
		{
			bool sent = (Utils.GetFirstPropertyOfParent (hit, "fixme:isSent") != null);
			string address = sent ? Utils.GetFirstPropertyOfParent (hit, "fixme:to") : Utils.GetFirstPropertyOfParent (hit, "fixme:from");

			if (address == null)
				return "";
			if (address.IndexOf (" <") != -1)
				address = address.Substring (0, address.IndexOf (" <"));

			return address;
		}
Esempio n. 17
0
		public Video (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Group = TileGroup.Video;

			Title = Hit ["beagle:ExactFilename"];

			if (! String.IsNullOrEmpty (Hit ["fixme:video:codec"]))
				Description = Hit ["fixme:video:codec"];
			
			if (! String.IsNullOrEmpty (Hit ["fixme:video:width"]))
				Description += String.Format (" ({0}x{1})", Hit ["fixme:video:width"], Hit ["fixme:video:height"]);			
		}
Esempio n. 18
0
		public override bool Validate (Beagle.Hit hit)
		{
			if (! base.Validate (hit))
				return false;
			
			if (hit ["beagle:FileType"] != "documentation")
				return false;
			
			Weight += 2;

			return true;
		}
Esempio n. 19
0
		public Calendar (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Group = TileGroup.Calendar;

			string summary = hit.GetFirstProperty ("fixme:summary");
			string time = Utils.NiceShortDate (hit.GetFirstProperty ("fixme:starttime"));

			Title = (time == "") ? summary : time + ": " + summary;

			if (!String.IsNullOrEmpty (hit.GetFirstProperty ("fixme:description")))
				Description = Utils.TrimFirstLine (hit.GetFirstProperty ("fixme:description"));
		}
Esempio n. 20
0
		public override bool Validate (Beagle.Hit hit)
		{
			if (! base.Validate (hit))
				return false;

			string str = hit.GetFirstProperty ("parent:fixme:hasAttachments");
			if (hit.ParentUri == null || str == null || str == "false")
				return false;

			Weight += 1;
			
			return true;
		}
Esempio n. 21
0
 public virtual void Bind(Beagle robot, Joystick joystick)
 {
     if (robot == null)
     {
         throw new ArgumentNullException("robot");
     }
     if (joystick == null)
     {
         throw new ArgumentNullException("joystick");
     }
     _robot    = robot;
     _joystick = joystick;
 }
Esempio n. 22
0
		public TextDocument (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Group = TileGroup.Documents;

			if (Hit ["fixme:page-count"] != null) {
				int count = Int32.Parse (Hit ["fixme:page-count"]);
				Description = String.Format (Catalog.GetPluralString ("{0} page", "{0} pages", count), count);
			}
			
			// These files generally have a default title or an auto-generated title.
			// So use the filename for these types of files.
			Title = hit.GetFirstProperty ("beagle:ExactFilename");
		}
Esempio n. 23
0
		public WebHistory (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Group = TileGroup.Website;

			string title = hit.GetFirstProperty ("dc:title");
			if (String.IsNullOrEmpty (title))
				title = Hit.Uri.Host;

			Title = title;
			Description = hit.Uri.ToString ();

			AddAction (new TileAction ("Find more from same host", Gtk.Stock.Find, FindFromHost));
		}
Esempio n. 24
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Beagle beagle = new Beagle();

            Console.WriteLine(beagle.IsHunter);
            Console.WriteLine(beagle.DoTrick());
            Console.WriteLine(beagle.EatFood());
            Console.WriteLine(beagle.FormsGroup());
            Console.WriteLine(beagle.MakesBabies());
            Console.WriteLine(beagle.LearnTrick());

            Husky husky = new Husky();

            Console.WriteLine(husky.LovesSnow);
            Console.WriteLine(husky.DoTrick());
            Console.WriteLine(husky.EatFood());
            Console.WriteLine(husky.FormsGroup());
            Console.WriteLine(husky.MakesBabies());
            Console.WriteLine(husky.LearnTrick());

            Chimpanzee chimp = new Chimpanzee();

            Console.WriteLine(chimp.HasHeart);
            Console.WriteLine(chimp.NumberOfLegs);
            Console.WriteLine(chimp.EatFood());
            Console.WriteLine(chimp.FormsGroup());
            Console.WriteLine(chimp.MakesBabies());
            Console.WriteLine(beagle.MakeSound());

            Dolphin dolphin = new Dolphin();

            Console.WriteLine(dolphin.HasHeart);
            Console.WriteLine(dolphin.BreathesAir);
            Console.WriteLine(dolphin.HasScales);
            Console.WriteLine(dolphin.DoTrick());
            Console.WriteLine(dolphin.EatFood());
            Console.WriteLine(dolphin.EatsHumans());
            Console.WriteLine(dolphin.MakesBabies());
            Console.WriteLine(dolphin.MakeSound());

            Shark shark = new Shark();

            Console.WriteLine(shark.HasHeart);
            Console.WriteLine(shark.BreathesAir);
            Console.WriteLine(shark.HasScales);
            Console.WriteLine(shark.EatFood());
            Console.WriteLine(shark.EatsHumans());
            Console.WriteLine(shark.MakeSound());
        }
Esempio n. 25
0
		public Manpage (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			if (! String.IsNullOrEmpty (hit.GetFirstProperty ("dc:title")))
				Title = hit.GetFirstProperty ("dc:title");
			else
				Title = hit.GetFirstProperty ("beagle:ExactFilename");

			if (hit ["beagle:IsChild"] == "true")
				path =	hit.ParentUri.LocalPath;
			else
				path = hit.Uri.LocalPath;

			Description = hit.GetFirstProperty ("dc:subject") ?? Catalog.GetString ("Manual page");
		}
Esempio n. 26
0
		public MailAttachment (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Group = TileGroup.Documents;
			Title = Hit ["fixme:attachment_title"];

			if (String.IsNullOrEmpty (Title))
				Title = Catalog.GetString (String.Format ("Attachment to \"{0}\"", Hit ["parent:dc:title"]));

			Description = Catalog.GetString ("Mail attachment");
			
			if ((Utils.GetFirstPropertyOfParent (hit, "fixme:isSent") == null)){
				AddAction ( new TileAction (Catalog.GetString ("Find Messages From Sender"), Gtk.Stock.Find, FindAllFromSender));
			}
		}
Esempio n. 27
0
		protected TileFlat (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Subject = WidgetFu.NewLabel ();
			WidgetFu.EllipsizeLabel (Subject, 40);
			HBox.PackStart (Subject, true, true, 3);

			From = WidgetFu.NewLabel ();
			From.UseMarkup = true;
			WidgetFu.EllipsizeLabel (From, 20);
			HBox.PackStart (From, false, false, 3);

			Date = WidgetFu.NewLabel ();
			HBox.PackStart (Date, false, false, 3);

			HBox.ShowAll ();
		}
Esempio n. 28
0
		// invalid .desktop files get filtered out by Validate(), so they won't
		// show up as Application tiles, but will show up as File tiles. But
		// valid .desktop files marked to not show up in GNOME get eaten by
		// BuildTile instead, so that they won't get picked up by the File tile.

		// FIXME: we shouldn't be hardcoding GNOME in BuildTile, it should depend
		// on what the running desktop is.

		public override bool Validate (Beagle.Hit hit)
		{
			if (!base.Validate (hit))
				return false;

			ditem = gnome_desktop_item_new_from_uri (hit.EscapedUri, 0, IntPtr.Zero);
			if (ditem == IntPtr.Zero)
				return false;
			
			// Make sure this is a real desktop file, not a .desktop.in
			string _name = gnome_desktop_item_get_string (ditem, "_Name");
			if (_name != null)
				return false;

			return true;
		}
Esempio n. 29
0
		public bool SetThumbnailIcon (Gtk.Image image, Beagle.Hit hit, int size)
		{
			DateTime mtime = (hit.FileInfo != null) ? hit.FileInfo.LastWriteTime : DateTime.Now;

			if (hit.MimeType == null ||
			    !factory.CanThumbnail (hit.EscapedUri, hit.MimeType, mtime))
				return false;

			string thumbnail = Gnome.Thumbnail.PathForUri (hit.EscapedUri, Gnome.ThumbnailSize.Normal);
			bool failed_thumb = factory.HasValidFailedThumbnail (hit.EscapedUri, mtime);

			if (! File.Exists (thumbnail) && ! failed_thumb) {
				lock (in_queue) {
					in_queue.Add (new ThumbnailRequest (image, thumbnail, hit, size));
					if (thread == null) {
						thread = new Thread (GenerateThumbnails);
						thread.Start ();
					}
				}
				return false;
			}

			if (failed_thumb)
				return false;

			Gdk.Pixbuf icon = new Gdk.Pixbuf (thumbnail);
			if (icon == null)
				return false;

			int width = icon.Width, height = icon.Height;
			if (icon.Height > size) {
				if (icon.Width > icon.Height) {
					width = size;
					height = (size * icon.Height) / icon.Width;
				} else {
					height = size;
					width = (size * icon.Width) / icon.Height;
				}
			} else if (icon.Width > size) {
				width = size;
				height = (size * icon.Height) / icon.Width;
			}
			icon = icon.ScaleSimple (width, height, Gdk.InterpType.Bilinear);

			image.Pixbuf = icon;
			return true;
		}
Esempio n. 30
0
		public Image (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Group = TileGroup.Image;

			Title = Hit ["beagle:ExactFilename"];

			if (Hit ["beagle:FilenameExtension"] != null && Hit ["beagle:FilenameExtension"].Length > 0)
				Description = Hit ["beagle:FilenameExtension"].Substring (1).ToUpper ();
			
			if (Hit ["fixme:width"] != null && Hit ["fixme:width"] != "")
				Description += String.Format (" {0}x{1}", Hit ["fixme:width"], Hit ["fixme:height"]);

			Description += String.Format (" ({0})", StringFu.FileLengthToString (Hit.FileInfo.Length));

			// AddAction (new TileAction (Catalog.GetString ("Add to Library"), Gtk.Stock.Add, AddToLibrary));
			AddAction (new TileAction (Catalog.GetString ("Set as Wallpaper"), SetAsWallpaper));
		}
Esempio n. 31
0
		public Folder (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Group = TileGroup.Folder;
			Title = Hit ["beagle:ExactFilename"];
			EnableOpenWith = true;
			
			int n = Hit.DirectoryInfo.GetFileSystemInfos ().Length;

			if (n == 0)
				Description = Catalog.GetString ("Empty");
			else
				Description = String.Format (Catalog.GetPluralString ("Contains {0} Item",
										      "Contains {0} Items", n), n);

			// FIXME: s/"gtk-info"/Gtk.Stock.Info/ when we can depend on gtk# 2.8
			//AddAction (new TileAction (Catalog.GetString ("Show Information"), "gtk-info", ShowInformation));
			AddAction (new TileAction (Catalog.GetString ("Move to Trash"), Gtk.Stock.Delete, MoveToTrash));
		}
Esempio n. 32
0
		public override bool Validate (Beagle.Hit hit)
		{
			if (! base.Validate (hit))
				return false;
			
			// FIXME: We should be using the users locale and
			// if we fail to find a result fallback to the C locale.
			// However, there is no easy way of doing this now.
			// Environment.GetEnvironmentVariable ("LANG"))

			if (String.IsNullOrEmpty (hit ["fixme:language"]))
				return true;

			if (hit ["fixme:language"] == "C" || hit ["fixme:language"] == "en")
				return true;

			return false;
		}
Esempio n. 33
0
		public Audio (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Group = TileGroup.Audio;

			// FIXME: Show album art if any. Needs implementation in Beagle.Util

			string title = Hit.GetFirstProperty ("dc:title");
			if (String.IsNullOrEmpty (title))
				title = Hit.GetFirstProperty ("fixme:title");

			if (! String.IsNullOrEmpty (title))
				Title = title;

			string artist = Hit.GetFirstProperty ("fixme:artist");
			if (! String.IsNullOrEmpty (artist))
				Description = artist;

			//AddAction (new TileAction (Catalog.GetString ("Add to Library"), AddToLibrary));
		}
Esempio n. 34
0
		public override bool Validate (Beagle.Hit hit)
		{
			if (! base.Validate (hit))
				return false;
			
			if (hit ["beagle:HitType"] == "File") {
				// This handles a case when a file with the
				// message/rfc822 mimetype is indexed without
				// gmime. Thus we fail to extract any info and
				// this tile is useless.
				string subject = hit.GetFirstProperty ("dc:title");
				
				if (subject != null && subject != "")
					return true;

				return false;
			}

			return true;
		}
Esempio n. 35
0
		public TileTemplate (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Alignment alignment = new Alignment (0.0f, 0.5f, 1.0f, 0.0f);
			HBox.PackStart (alignment, true, true, 0);

			VBox vbox = new VBox (false, 0);
			alignment.Add (vbox);

			title_label = WidgetFu.NewLabel ();
			title_label.LineWrap = true;
			WidgetFu.EllipsizeLabel (title_label, 30);
			vbox.PackStart (title_label, false, false, 0);

			desc_label = WidgetFu.NewGrayLabel ();
			desc_label.NoShowAll = true;
			WidgetFu.EllipsizeLabel (desc_label, 30);
			vbox.PackStart (desc_label, false, false, 0);

			alignment.ShowAll ();
		}
Esempio n. 36
0
		public TileFile (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
		{
			Title = GetTitle (hit);
			
			if (Hit.FileInfo != null) {
				Timestamp = Hit.FileInfo.LastWriteTimeUtc;
				Description = Utils.NiceShortDate (Timestamp);
			}

			AddAction (new TileAction (Catalog.GetString ("Reveal in Folder"), RevealInFolder));
			AddAction (new TileAction (Catalog.GetString ("E-Mail"), Email));
			// AddAction (new TileAction (Catalog.GetString ("Instant-Message"), InstantMessage));
			AddAction (new TileAction (Catalog.GetString ("Move to Trash"), Gtk.Stock.Delete, MoveToTrash));

			if (! String.IsNullOrEmpty (Hit.GetFirstProperty ("dc:author"))) {
				AddAction(new TileAction (Catalog.GetString ("Find Documents From Same Author"), Gtk.Stock.Find, FindSameAuthor));
			}

			EnableOpenWith = true;
		}
Esempio n. 37
0
 public override void Bind(Beagle robot, Joystick joystick)
 {
     base.Bind(robot, joystick);
     DataContext = robot;
 }
Esempio n. 38
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // =============================================================================================================
            // Reset
            // =============================================================================================================

            DA.GetData <bool>("Reset", ref iReset);

            if (iReset)
            {
                DA.GetData <SpringMesh>("Spring Mesh", ref iSpringMesh);
                DA.GetData <int>("Population Size", ref iPopulationSize);

                triangleCentres = new List <Point3d>();
                trianglePlanes  = new List <Plane>();
                triangleNormals = new List <Vector3d>();
                for (int i = 0; i < iSpringMesh.Triangles.Count; i++)
                {
                    triangleCentres.Add(iSpringMesh.ComputeCircumscribedCircleCenter(i));
                    trianglePlanes.Add(new Plane(
                                           iSpringMesh.Vertices[iSpringMesh.Triangles[i].FirstVertexIndex].Position,
                                           iSpringMesh.Vertices[iSpringMesh.Triangles[i].SecondVertexIndex].Position,
                                           iSpringMesh.Vertices[iSpringMesh.Triangles[i].ThirdVertexIndex].Position
                                           ));
                    triangleNormals.Add(iSpringMesh.ComputeTriangleNormal(i));
                }

                edgeXAxes   = new List <Vector3d>();
                edgeYAxes   = new List <Vector3d>();
                edgeZAxes   = new List <Vector3d>();
                edgePlanes  = new List <Plane>();
                edgeOrigins = new List <Point3d>();

                List <double> geneMinValues = new List <double>();
                List <double> geneMaxValues = new List <double>();

                foreach (Edge edge in iSpringMesh.Edges)
                {
                    if (edge.SecondTriangleIndex >= 0)
                    {
                        Vector3d edgeXAxis = iSpringMesh.Vertices[edge.SecondVertexIndex].Position - iSpringMesh.Vertices[edge.FirstVertexIndex].Position;
                        edgeXAxes.Add(edgeXAxis);

                        Vector3d edgeZAxis = triangleNormals[edge.FirstTriangleIndex] + triangleNormals[edge.SecondTriangleIndex];
                        edgeZAxis.Unitize();
                        edgeZAxes.Add(edgeZAxis);

                        Vector3d edgeYAxis = Vector3d.CrossProduct(edgeZAxis, edgeXAxis);
                        edgeYAxes.Add(edgeYAxis);

                        Point3d edgePlaneOrigin = 0.5 * (iSpringMesh.Vertices[edge.FirstVertexIndex].Position + iSpringMesh.Vertices[edge.SecondVertexIndex].Position);

                        edgeOrigins.Add(edgePlaneOrigin);


                        edgePlanes.Add(new Plane(edgePlaneOrigin, edgeXAxis, edgeYAxis));

                        double angle = Utils.AngleBetweenTwoUnitVectors(edgeZAxis, triangleNormals[edge.FirstTriangleIndex]);

                        geneMinValues.Add(-angle);
                        geneMaxValues.Add(angle);
                    }
                    else
                    {
                        Vector3d edgeXAxis = iSpringMesh.Vertices[edge.SecondVertexIndex].Position - iSpringMesh.Vertices[edge.FirstVertexIndex].Position;
                        edgeXAxes.Add(edgeXAxis);

                        Vector3d edgeZAxis = triangleNormals[edge.FirstTriangleIndex];
                        if (edgeZAxis.Z < 0.0)
                        {
                            edgeZAxis += -Vector3d.ZAxis;
                        }
                        else
                        {
                            Vector3d temp = new Vector3d(-edgeZAxis.X, -edgeZAxis.Y, 0.0);
                            temp.Unitize();
                            edgeZAxis += temp;
                        }

                        edgeZAxis.Unitize();
                        edgeZAxes.Add(edgeZAxis);

                        Vector3d edgeYAxis = Vector3d.CrossProduct(triangleNormals[edge.FirstTriangleIndex], edgeXAxis);
                        edgeYAxes.Add(edgeYAxis);

                        Point3d edgePlaneOrigin = 0.5 * (iSpringMesh.Vertices[edge.FirstVertexIndex].Position + iSpringMesh.Vertices[edge.SecondVertexIndex].Position);

                        edgeOrigins.Add(edgePlaneOrigin);

                        edgePlanes.Add(new Plane(edgePlaneOrigin, edgeXAxis, edgeYAxis));

                        double angle = Utils.AngleBetweenTwoUnitVectors(edgeZAxis, triangleNormals[edge.FirstTriangleIndex]);

                        geneMinValues.Add(-angle);
                        geneMaxValues.Add(angle);
                    }
                }

                beagle = new Beagle(iPopulationSize, geneMinValues, geneMaxValues);

                foreach (Genome genome in beagle.Genomes)
                {
                    computeFitness(genome);
                }

                goto Conclusion;
            }


            DA.GetData <bool>("Play", ref iPlay);

            if (iPlay)
            {
                ExpireSolution(true);
            }
            else
            {
                List <double> values = new List <double>();
                foreach (Gene gene in beagle.Genomes[0].Genes)
                {
                    values.Add(gene.Value);
                }
                DA.SetDataList(4, values);
                goto Conclusion;
            }
            //if (!iPlay) goto Conclusion;


            // ====================================================================================================
            // Evolution
            // ====================================================================================================

            DA.GetData <int>("Subiteration Count", ref iSubiterationCount);
            DA.GetData <double>("Max. Coupling Distance", ref iMaxCouplingDistance);
            DA.GetData <double>("Mutation Rate", ref iMutationRate);
            DA.GetData <double>("Mutation Amount", ref iMutationAmount);

            beagle.MaxCouplingDistance = iMaxCouplingDistance;
            beagle.MutationRate        = iMutationRate;
            beagle.MutationAmount      = iMutationAmount;

            for (int i = 0; i < iSubiterationCount; i++)
            {
                beagle.SelectParents();
                beagle.Reproduce();

                for (int j = beagle.PopulationSize; j < beagle.Genomes.Count; j++)
                {
                    computeFitness(beagle.Genomes[j]);
                }

                beagle.SelectFittests();
            }

            DA.SetDataList(3, new List <double> {
                beagle.Genomes[0].Fitness
            });

            // ====================================================================================================
            // Conclusion
            // ====================================================================================================

Conclusion:

            Genome bestGenome = beagle.Genomes[0];

            for (int i = 0; i < bestGenome.Genes.Count; i++)
            {
                double angle = bestGenome.Genes[i].Value;

                Vector3d planeNormal = Math.Sin(angle) * edgeYAxes[i] + Math.Cos(angle) * edgeZAxes[i];

                edgePlanes[i] = new Plane(
                    edgePlanes[i].Origin,
                    edgePlanes[i].XAxis,
                    Vector3d.CrossProduct(planeNormal, edgePlanes[i].XAxis)
                    );
            }

            //List<Plane> nastyPlanes = new List<Plane>();
            List <Point3d> planeTripletIntersections = new List <Point3d>();

            foreach (Triangle triangle in iSpringMesh.Triangles)
            {
                Point3d intersectionPoint;
                if (Intersection.PlanePlanePlane(edgePlanes[triangle.FirstEdgeIndex], edgePlanes[triangle.SecondEdgeIndex], edgePlanes[triangle.ThirdEdgeIndex], out intersectionPoint))
                {
                    planeTripletIntersections.Add(intersectionPoint);
                }
                //else
                //{
                //    nastyPlanes.Add(edgePlanes[triangle.FirstEdgeIndex]);
                //    nastyPlanes.Add(edgePlanes[triangle.FirstEdgeIndex]);
                //    nastyPlanes.Add(edgePlanes[triangle.FirstEdgeIndex]);
                //}
            }

            DA.SetDataList(1, edgePlanes);
            DA.SetDataList(2, planeTripletIntersections);



            //DA.SetDataList(1, edgePlanes);
            //DA.SetDataList(2, edgeOrigins);
            //DA.SetDataList(3, edgeXAxes);
            //DA.SetDataList(4, edgeYAxes);
            //DA.SetDataList(5, edgeZAxes);
        }
Esempio n. 39
0
 public override void Bind(Beagle robot, Joystick joystick)
 {
     base.Bind(robot, joystick);
     joystick.MainAxisChanged += Joystick_MainAxisChanged;
 }
Esempio n. 40
0
 public override void Bind(Beagle robot, Joystick joystick)
 {
     base.Bind(robot, joystick);
     joystick.TriggerPressed += joystick_TriggerClicked;
     DataContext              = robot.UltrasonicRangeFinder;
 }