Exemplo n.º 1
0
 private void OnRobotChange(object sender, TopBar.RobotChangeEventArgs e)
 {
     try
     {
         if (connectionThread == null || connectionThread.IsAlive == false)
         {
             currentConfig    = e.ConfigFiles;
             connectionThread = new Thread(new ThreadStart(delegate() { connect(); }));
             connectionThread.Start();
         }
         else
         {
             e.Cancel = true;
         }
     }
     catch (Exception err)
     {
         GUIUtilities.ReportUnexpectedException(err);
     }
 }
Exemplo n.º 2
0
 private void OnTextChanged(object sender, TextChangedEventArgs e)
 {
     try
     {
         if (currentConfigFiles != null)
         {
             if (
                 (sender == FriendlyNameBox && (!currentConfigFiles.MyroConfiguration.FriendlyName.Equals(FriendlyNameBox.Text))) ||
                 (sender == HttpPortBox && (!currentConfigFiles.MyroConfiguration.HttpPort.ToString().Equals(HttpPortBox.Text))) ||
                 (sender == DsspPortBox && (!currentConfigFiles.MyroConfiguration.DsspPort.ToString().Equals(DsspPortBox.Text))))
             {
                 currentModified = true;
                 setModifiedStyle();
             }
         }
     }
     catch (Exception err)
     {
         GUIUtilities.ReportUnexpectedException(err);
     }
 }
Exemplo n.º 3
0
        //private void OnBrowseManifest(object sender, ExecutedRoutedEventArgs e)
        //{
        //    var dlg = new OpenFileDialog();
        //    if (curManifest != null && curManifest.Length > 0)
        //        dlg.FileName = curManifest;
        //    dlg.DefaultExt = ".manifest.xml";
        //    dlg.Filter = "DSS Manifest (.manifest.xml)|*.manifest.xml";
        //    if (dlg.ShowDialog(this) == true)
        //    {
        //        lock (connectionThreadLock)
        //        {
        //            curManifest = dlg.FileName;
        //            if (connectionThread == null || connectionThread.IsAlive == false)
        //            {
        //                connectionThread = new Thread(new ThreadStart(delegate() { connect(); }));
        //                connectionThread.Start();
        //            }
        //        }
        //    }
        //}

        //private void ToggleConnect(object sender, RoutedEventArgs e)
        //{
        //    if (curManifest == null || curManifest.Length <= 0)
        //        BrowseManifest(sender, e);

        //    lock (connectionThreadLock)
        //    {
        //        if (connectionThread == null || connectionThread.IsAlive == false)
        //        {
        //            connectionThread = new Thread(new ThreadStart(delegate() { connect(); }));
        //            connectionThread.Start();
        //        }
        //    }
        //}

        private void OnInitialized(object sender, EventArgs e)
        {
            try
            {
                Robot.RobotStateChangeEvent += OnRobotStateChange;

                commandWindow.StartScripting();
                commandWindow.PythonExecuting +=
                    delegate(object source, EventArgs e2)
                {
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                                      new ThreadStart(delegate() { topBar.IsRunning = true; }));
                };
                commandWindow.PythonFinished +=
                    delegate(object source, EventArgs e2)
                {
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                                      new ThreadStart(delegate() { topBar.IsRunning = false; }));
                };
                editor = new Editor(this);
                editor.InsertedEditor  += OnEditorInserted;
                editor.RemovedEditor   += OnEditorRemoved;
                editor.ActivatedEditor += OnEditorActivated;
                editor.ModifiedChanged += OnEditorNameChanged;
                editor.NameChanged     += OnEditorNameChanged;
                //SetButtonsEnabled();

                editor.RequestNewDocument();

                webcamDisplay.StartUpdate();

                simDisplay = new SimulatorDisplay();
                simDisplay.SimulatorFound += OnFoundSimulator;
                simDisplay.Start();
            }
            catch (Exception err)
            {
                GUIUtilities.ReportUnexpectedException(err);
            }
        }
Exemplo n.º 4
0
 private void OnEditorInserted(object sender, Editor.EditorEventArgs e)
 {
     try
     {
         var header = new Grid();
         header.Children.Add(new Label()
         {
             Content = e.Document.FileName
         });
         header.Children.Add(new Button()
         {
             Content = new Image()
             {
                 Source = new BitmapImage(new Uri("cross.png", UriKind.Relative))
             }
         });
         var item = new CloseableTabItemDemo.CloseableTabItem()
         {
             Header  = e.Document.FileName,
             Content = e.Document.EditorControl
         };
         item.GotFocus +=
             delegate(object sender2, RoutedEventArgs e2)
         {
             e.Document.EditorControl.Focus();
         };
         item.CloseTab +=
             delegate(object sender2, RoutedEventArgs e2)
         {
             editor.RequestClose(e.Document);
         };
         mainTabs.Items.Add(item);
         mainTabs.SelectedIndex = mainTabs.Items.Count - 1;
     }
     catch (Exception err)
     {
         GUIUtilities.ReportUnexpectedException(err);
     }
 }
Exemplo n.º 5
0
        private void OnClosing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            try
            {
                if (editor.RequestCloseAll() == false)
                {
                    e.Cancel = true;
                }
            }
            catch (Exception err)
            {
                GUIUtilities.ReportUnexpectedException(err);
                e.Cancel = true;
                return;
            }

            this.IsEnabled = false;
            Window closing = new ClosingWindow();

            closing.Show();
            try
            { controlPanel.Dispose(); }
            catch (Exception err) { GUIUtilities.ReportUnexpectedException(err); }
            try
            { commandWindow.Dispose(); }
            catch (Exception err) { GUIUtilities.ReportUnexpectedException(err); }
            try
            { webcamDisplay.Dispose(); }
            catch (Exception err) { GUIUtilities.ReportUnexpectedException(err); }
            try
            { simDisplay.Dispose(); }
            catch (Exception err) { GUIUtilities.ReportUnexpectedException(err); }
            try
            { Robot.Shutdown(); }
            catch (Exception err) { GUIUtilities.ReportUnexpectedException(err); }
            closing.Close();
        }
Exemplo n.º 6
0
        //private void disconnect()
        //{
        //    Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
        //        new ThreadStart(delegate()
        //        {
        //            manifestBox.Text = "Disconnecting from robot...";
        //        }));
        //    controlPanel.SetRobot(null);
        //    if (robot != null)
        //        robot.Shutdown();
        //    robot = null;
        //    Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
        //        new ThreadStart(delegate()
        //        {
        //            controlPanel.IsEnabled = false;
        //            try
        //            {
        //                ((Image)connectButton.Content).Source = new BitmapImage(new Uri("disconnect.png", UriKind.Relative));
        //                manifestBox.Text = (curManifest == null ? "Disconnected" : curManifest + " (disconnected)");
        //            }
        //            catch (Exception e) { Console.WriteLine(e); }
        //        }));
        //}

        private void connect()
        {
            try
            {
                if (connected == false && currentConfig != null)
                {
                    Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                           new ThreadStart(delegate()
                    {
                        //manifestBox.Text = "Connecting to robot...";
                        commandWindow.ExecuteCommand("from myro import *");
                        commandWindow.LogText("> init('" + currentConfig.BaseName + "')\n", Colors.MediumBlue);
                    }));
                    Robot.Init(currentConfig.ManifestFilePath,
                               currentConfig.MyroConfiguration.HttpPort,
                               currentConfig.MyroConfiguration.DsspPort);
                    controlPanel.SetRobot();
                    Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                           new ThreadStart(delegate()
                    {
                        controlPanel.IsEnabled = true;
                        try
                        {
                            //((Image)connectButton.Content).Source = new BitmapImage(new Uri("connected.png", UriKind.Relative));
                            //manifestBox.Text = (curManifest == null ? "" : curManifest);
                        }
                        catch (Exception e) { Console.WriteLine(e); }
                    }));
                }
            }
            catch (Exception e)
            {
                Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                                  new ThreadStart(delegate() { GUIUtilities.ReportUnexpectedException(e); }));
            }
        }
Exemplo n.º 7
0
 private void reset()
 {
     if (livePanelList.Count > 0)
     {
         Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                           new ThreadStart(delegate()
         {
             try
             {
                 foreach (var pi in livePanelList)
                 {
                     servicePanel.Children.Remove(pi.Group);
                 }
             }
             catch (Exception e)
             {
                 GUIUtilities.ReportUnexpectedException(e);
                 //Console.WriteLine(e.ToString());
             }
         }));
     }
     panelList = origPanelList;
     livePanelList.Clear();
 }
Exemplo n.º 8
0
        private void checkNewPanels()
        {
            List <ServicePanelInfo> toRemove = new List <ServicePanelInfo>();
            List <Thread>           threads  = new List <Thread>();

            foreach (var pi in panelList)
            {
                var    myPi = pi;
                Thread t    = new Thread(new ThreadStart(
                                             delegate()
                {
                    try
                    {
                        //Console.WriteLine("Adding " + myPi.Name);
                        Robot.GetNames(myPi.Name);
                        lock (toRemove) { toRemove.Add(myPi); }
                    }
                    catch (Exception) { }
                }));
                t.Start();
                threads.Add(t);
            }
            foreach (var t in threads)
            {
                t.Join();
            }
            ManualResetEvent signal = new ManualResetEvent(false);

            Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                   new ThreadStart(delegate()
            {
                try
                {
                    var newLivePanelList = new List <ServicePanelInfo>(livePanelList);
                    foreach (var pi in toRemove)
                    {
                        pi.Meters = new CircleMeters()
                        {
                            //Width = 200,
                            //Height = 30,
                        };
                        var myPi = pi;
                        pi.Meters.ValueChange += (CircleMeters.ValueChangeHandler)
                                                 delegate(object sender, Myro.GUI.WPFControls.CircleMeters.ValueChangeArgs e)
                        {
                            Robot.Set(myPi.Name, e.Index, e.Value);
                        };
                        pi.Meters.SetColor(pi.Color);
                        pi.Group = new GroupBox()
                        {
                            Header = pi.Description,
                            Margin = new Thickness(5.0, 5.0, 5.0, 10.0),
                            HorizontalAlignment        = HorizontalAlignment.Stretch,
                            VerticalAlignment          = VerticalAlignment.Top,
                            HorizontalContentAlignment = HorizontalAlignment.Stretch,
                            Content = pi.Meters
                        };
                        newLivePanelList.Add(pi);
                        panelList.Remove(pi);
                        servicePanel.Children.Add(pi.Group);
                    }
                    // Swap in reference to new list, changed atomically because updateLoop
                    // may be using the list to update sensor readings
                    livePanelList = newLivePanelList;
                }
                catch (Exception e)
                {
                    GUIUtilities.ReportUnexpectedException(e);
                    //Console.WriteLine(e.ToString());
                    //throw;
                }
                finally { signal.Set(); }
            }));
            signal.WaitOne();
        }