public MainWindow() { new Thread(() => { ROS.Init(new string[0], "dynamic_reconfigure_sharp_" + Environment.MachineName); nh = new NodeHandle(); Dispatcher.Invoke(new Action(() => { ConnecitonLabel.Content = "Connected"; })); }).Start(); try { InitializeComponent(); System.Diagnostics.PresentationTraceSources.DataBindingSource.Switch.Level = System.Diagnostics.SourceLevels.Critical; TargetBox.ItemsSource = knownConfigurations.Keys; knownConfigurations.Add("-", null); TargetBox.SelectedIndex = 0; } catch (Exception e) { EDB.WriteLine(e); Close(); } topicPoller = new Thread(() => { while (ROS.ok && !ROS.shutting_down) { TopicInfo[] topics = new TopicInfo[0]; master.getTopics(ref topics); string[] nodes = new string[0]; master.getNodes(ref nodes); List <string> prevlist = new List <string>(knownConfigurations.Keys); List <string> additions = new List <string>(); foreach (TopicInfo ti in topics) { if (ti.data_type == "dynamic_reconfigure/Config") { string prefix = ti.name.Replace("/parameter_updates", ""); if (!knownConfigurations.ContainsKey(prefix)) { additions.Add(prefix); } else { prevlist.Remove(prefix); } } } lock (this) { if (!ROS.ok || ROS.shutting_down) { return; } foreach (string prefix in additions) { string pfx = prefix; Dispatcher.Invoke(new Action(() => { knownConfigurations.Add(pfx, null); }), new TimeSpan(0, 0, 0, 1)); } } Dispatcher.Invoke(new Action(TargetBox.Items.Refresh)); foreach (string s in prevlist) { if (!s.Equals("-")) { string pfx = s; Dispatcher.Invoke(new Action(() => { if (reconfigureview != null && s.Equals(reconfigureview.Namespace)) { reconfigureview.Namespace = null; } if (TargetBox.SelectedItem != null && ((string)TargetBox.SelectedItem).Equals(pfx)) { TargetBox.SelectedIndex = 0; } lock (this) { knownConfigurations.Remove(pfx); } }), new TimeSpan(0, 0, 0, 1)); } } Dispatcher.Invoke(new Action(TargetBox.Items.Refresh)); if (reconfigureview == null && nh != null) { Dispatcher.Invoke(new Action(() => { string target = null; if (TargetBox.SelectedItem != null && !String.Equals(TargetBox.SelectedItem.ToString(), "-")) { target = TargetBox.SelectedItem.ToString(); } reconfigureview = new DynamicReconfigurePage(nh, target); PageContainer.Children.Add(reconfigureview); })); } Thread.Sleep(500); } }); topicPoller.Start(); }
public MainWindow() { ROS.Init(new string[0], "dynamic_reconfigure_sharp_" + Environment.MachineName); nh = new NodeHandle(); try { InitializeComponent(); } catch (Exception e) { Console.WriteLine(e); Close(); } topicPoller = new Thread(() => { while (ROS.ok) { Dispatcher.Invoke(new Action(() => { lock (this) { if (!ROS.ok) { return; } TopicInfo[] topics = new TopicInfo[0]; master.getTopics(ref topics); List <string> prevlist = new List <string>(knownConfigurations.Keys); bool changed = false; foreach (TopicInfo ti in topics) { if (ti.data_type == "dynamic_reconfigure/Config") { string prefix = ti.name.Replace("/parameter_updates", ""); prevlist.Remove(prefix); if (!knownConfigurations.ContainsKey(prefix)) { DynamicReconfigurePage drp = new DynamicReconfigurePage(nh, prefix); TargetBox.Items.Add(prefix); if (drp != null) { knownConfigurations.Add(prefix, drp); } changed = true; } } } foreach (string s in prevlist) { foreach (string S in TargetBox.Items) { if (S == s) { changed = true; TargetBox.Items.Remove(s); break; } } knownConfigurations.Remove(s); } if (changed) { string sel = (TargetBox.SelectedItem as string); List <string> keys = knownConfigurations.Keys.ToList(); keys.Sort(); TargetBox.Items.Clear(); string none = "None"; TargetBox.Items.Add(none); if (string.Equals(sel, none)) { TargetBox.SelectedIndex = TargetBox.Items.Count - 1; } foreach (string k in keys) { TargetBox.Items.Add(k); if (string.Equals(sel, k)) { TargetBox.SelectedIndex = TargetBox.Items.Count - 1; } } } } })); if (!ROS.ok) { return; } Thread.Sleep(1000); } }); topicPoller.Start(); }