Beispiel #1
0
        private void addCameraWatch(string cameraName, bool selectIfFound)
        {
            Delegate subscribeForEntity = new ThreadStart(delegate()
            {
                try
                {
                    SimulationEngine.GlobalInstancePort.Subscribe(new EntitySubscribeRequestType()
                    {
                        Name = cameraName
                    }, _notifyTarget);
                    Arbiter.Activate(queue, Arbiter.Receive <InsertSimulationEntity>(true, _notifyTarget,
                                                                                     delegate(InsertSimulationEntity ins) { AddCamera(ins.Body as CameraEntity, selectIfFound); }));
                }
                catch (Exception e)
                {
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                                      new ThreadStart(delegate() { GUIUtilities.ReportUnexpectedException(e); }));
                }
            });

            if (_notifyTarget != null && SimulationEngine.GlobalInstancePort != null)
            {
                Arbiter.Activate(queue, Arbiter.Choice(
                                     SimulationEngine.GlobalInstancePort.Query(
                                         new VisualEntity()
                {
                    EntityState = new EntityState()
                    {
                        Name = cameraName
                    }
                }),
                                     delegate(QuerySimulationEntityResponseType r)
                {
                    if (r.Entity != null)
                    {
                        var cam = r.Entity as CameraEntity;
                        if (cam != null)
                        {
                            AddCamera(cam, selectIfFound);
                        }
                        else
                        {
                            subscribeForEntity.DynamicInvoke();
                        }
                    }
                    else
                    {
                        subscribeForEntity.DynamicInvoke();
                    }
                },
                                     delegate(Fault f)
                {
                    subscribeForEntity.DynamicInvoke();
                }));
            }
        }
Beispiel #2
0
 private void SimulatorContainer_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         initBitmap();
     }
     catch (Exception err)
     {
         GUIUtilities.ReportUnexpectedException(err);
     }
 }
Beispiel #3
0
 private void OnMouseUp(object sender, MouseButtonEventArgs e)
 {
     try
     {
         SimulatorContainer.ReleaseMouseCapture();
     }
     catch (Exception err)
     {
         GUIUtilities.ReportUnexpectedException(err);
     }
 }
Beispiel #4
0
 private void OnResize(object sender, SizeChangedEventArgs e)
 {
     try
     {
         sizeChangePort.Post(e.NewSize);
     }
     catch (Exception err)
     {
         GUIUtilities.ReportUnexpectedException(err);
     }
 }
Beispiel #5
0
 private void AddCamera_Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         AddContainer.Child = (UIElement)AddContainer.FindResource("textbox");
         AddContainer.Child.Focus();
     }
     catch (Exception err)
     {
         GUIUtilities.ReportUnexpectedException(err);
     }
 }
Beispiel #6
0
 private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     try
     {
         if (e.Key == Key.Escape)
         {
             AddContainer.Child = (UIElement)AddContainer.FindResource("button");
         }
     }
     catch (Exception err)
     {
         GUIUtilities.ReportUnexpectedException(err);
     }
 }
Beispiel #7
0
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                if (curCamera != null && SimulatorContainer.IsMouseCaptured)
                {
                    var p    = e.GetPosition(SimulatorContainer);
                    var drag = new Vector2((float)p.X - mouseStart.X, (float)p.Y - mouseStart.Y);
                    mouseStart = new Vector2((float)p.X, (float)p.Y);
                    xnaTypes.Vector3 view = curCamera.Camera.LookAt - curCamera.Camera.Location;
                    view.Normalize();
                    switch (dragType)
                    {
                    case DragType.LOOK:
                        xnaTypes.Vector3 up  = new xnaTypes.Vector3(0, 1, 0);
                        float            dot = xnaTypes.Vector3.Dot(view, up);
                        if (Math.Abs(dot) > 0.99)
                        {
                            up += new xnaTypes.Vector3(0.1f, 0, 0);
                            up.Normalize();
                        }
                        xnaTypes.Vector3 right = xnaTypes.Vector3.Cross(view, up);
                        view = xnaTypes.Vector3.Multiply(view, 10f);
                        view = xnaTypes.Vector3.Transform(view, xnaTypes.Matrix.CreateFromAxisAngle(up, (float)(-drag.X * Math.PI / 500)));
                        view = xnaTypes.Vector3.Transform(view, xnaTypes.Matrix.CreateFromAxisAngle(right, (float)(-drag.Y * Math.PI / 500)));

                        curCamera.Camera.LookAt = curCamera.Camera.Location + view;
                        break;

                    case DragType.MOVE:
                        var right2 = xnaTypes.Vector3.Cross(view, new xnaTypes.Vector3(0, 1, 0));
                        var up2    = xnaTypes.Vector3.Cross(right2, view);
                        right2 *= (drag.X * 0.05f);
                        up2    *= (-drag.Y * 0.05f);
                        var delta = right2 + up2;
                        curCamera.Camera.LookAt   += delta;
                        curCamera.Camera.Location += delta;
                        break;
                    }
                }
            }
            catch (Exception err)
            {
                GUIUtilities.ReportUnexpectedException(err);
            }
        }
Beispiel #8
0
 private void OnMouseWheel(object sender, MouseWheelEventArgs e)
 {
     try
     {
         if (curCamera != null)
         {
             xnaTypes.Vector3 view = curCamera.Camera.LookAt - curCamera.Camera.Location;
             view.Normalize();
             view = xnaTypes.Vector3.Multiply(view, e.Delta * 0.01f);
             curCamera.Camera.LookAt   += view;
             curCamera.Camera.Location += view;
         }
     }
     catch (Exception err)
     {
         GUIUtilities.ReportUnexpectedException(err);
     }
 }
Beispiel #9
0
        private void PlayTone(object sender, MouseEventArgs e)
        {
            double duration = durSlider.Value;
            double freq1    = (freq1Slider.Value == freq1Slider.Minimum ? 0.0 : freq1Slider.Value);
            double freq2    = (freq2Slider.Value == freq2Slider.Minimum ? 0.0 : freq2Slider.Value);

            new Thread(new ThreadStart(delegate()
            {
                try
                {
                    Robot.beep(duration, freq1, freq2);
                }
                catch (Exception err)
                {
                    Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                           new ThreadStart(delegate() { GUIUtilities.ReportUnexpectedException(err); }));
                }
            })).Start();
        }
Beispiel #10
0
 private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
 {
     try
     {
         var textbox = sender as TextBox;
         if (e.Text.EndsWith("\n") || e.Text.EndsWith("\r"))
         {
             if (textbox.Text.Length > 0)
             {
                 addCameraWatch(textbox.Text, true);
             }
             AddContainer.Child = (UIElement)AddContainer.FindResource("button");
         }
     }
     catch (Exception err)
     {
         GUIUtilities.ReportUnexpectedException(err);
     }
 }
Beispiel #11
0
 /// <summary>
 /// Helper method to clear the populated sensors so they can be
 /// repopulated.  This is currently not used, but was intended to
 /// be called when the connected robot changes.
 /// </summary>
 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);
             }
         }));
     }
     panelList = origPanelList;
     livePanelList.Clear();
 }
Beispiel #12
0
        private void SizeChangeHandler(Size size)
        {
            // Flush size change messages
            while (sizeChangePort.Test() != null)
            {
            }
            ;

            // Resize the bitmap for displaying camera images
            try
            { initBitmap(); }
            catch (Exception e) { GUIUtilities.ReportUnexpectedException(e); }

            Thread.Sleep(50);

            // Activate new receiver
            try
            {
                // This try is here because this will throw an exception when DSS shuts down.
                Arbiter.Activate(queue, Arbiter.Receive(false, sizeChangePort, SizeChangeHandler));
            }
            catch (Exception) { }
        }
Beispiel #13
0
        private void OnSimCamChange(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (SimCamBox.SelectedItem != null)
                {
                    ComboBoxItem item = SimCamBox.SelectedItem as ComboBoxItem;
                    if (item != null && item.Tag != null && item.Tag is CameraInfo)
                    {
                        // Set the current camera, subscribe it if it has not yet
                        // been subscribed, and set it's frame update rate.
                        curCamera = (CameraInfo)item.Tag;

                        // Clear the display in case the new images are smaller
                        initBitmap();
                    }
                }
            }
            catch (Exception err)
            {
                GUIUtilities.ReportUnexpectedException(err);
            }
        }
Beispiel #14
0
 private void OnMouseDown(object sender, MouseButtonEventArgs e)
 {
     try
     {
         if (!SimulatorContainer.IsMouseCaptured)
         {
             if (e.ChangedButton == MouseButton.Left)
             {
                 dragType = DragType.LOOK;
             }
             else if (e.ChangedButton == MouseButton.Right)
             {
                 dragType = DragType.MOVE;
             }
             var p = e.GetPosition(SimulatorContainer);
             mouseStart = new Vector2((float)p.X, (float)p.Y);
             SimulatorContainer.CaptureMouse();
         }
     }
     catch (Exception err)
     {
         GUIUtilities.ReportUnexpectedException(err);
     }
 }
Beispiel #15
0
        /// <summary>
        /// Helper method that checks for new sensor services having started.
        /// This is called every few seconds by the polling thread.
        /// </summary>
        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();
        }
Beispiel #16
0
 private void OnSnapClick(object sender, RoutedEventArgs e)
 {
     if (takePictureThread == null)
     {
         SnapshotButton.IsEnabled = false;
         takePictureThread        = new Thread(new ThreadStart(delegate()
         {
             try
             {
                 takePictureHelper();
             }
             catch (Exception err)
             {
                 Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                        new ThreadStart(delegate() { IsActive = false; GUIUtilities.ReportUnexpectedException(err); }));
             }
             finally
             {
                 Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                        new ThreadStart(delegate() { SnapshotButton.IsEnabled = true; }));
                 takePictureThread = null;
             }
         }));
         takePictureThread.Start();
     }
 }
Beispiel #17
0
 private void updateLoop()
 {
     while (!shouldExit)
     {
         if (IsActive && curType != null)
         {
             try
             {
                 if (setDarknessRequest >= 0)
                 {
                     if (setDarknessRequest == 256)
                     {
                         Robot.autoCamera();
                     }
                     else
                     {
                         Robot.darkenCamera((byte)setDarknessRequest);
                     }
                     setDarknessRequest = -1;
                 }
                 takePictureHelper();
             }
             catch (Exception e)
             {
                 Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                        new ThreadStart(delegate() { IsActive = false; GUIUtilities.ReportUnexpectedException(e); }));
             }
         }
         Thread.Sleep(delayMs);
     }
 }