public void DoRemove(object obj)
 {
     if(obj is MotionControllerViewModel)
     {
         MotionControllerViewModel mcvw = (MotionControllerViewModel) obj;
         mcvw.Cleanup();
     }
     else if (obj is CameraViewModel)
     {
         CameraViewModel scvw = (CameraViewModel) obj;
         scvw.Cleanup();
     }
     else if(obj is ClientViewModel)
     {
         ClientViewModel cvw = (ClientViewModel) obj;
         cvw.Cleanup();
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the AllCamerasViewModel class.
        /// </summary>
        public CamerasViewModel()
        {
            CamerasModel.Name = "all";
            CamerasModel.Cameras = new ObservableCollection<CameraModel>();
            CamerasModel.Controllers = new ObservableCollection<MotionControllerModel>();
            Refresh();
            MultipleViewsService = new MultipleViewsService();
            MultipleViewsService.Initialize(_camerasModel, CameraViewModels.Select(camera => camera.TrackerService).ToList());

            Messenger.Default.Register<AddCameraMessage>(this, message =>
            {
                CameraViewModel cvm = SimpleIoc.Default.GetInstance<CameraViewModel>(message.Camera.GUID);
                CameraViewModels.Add(cvm);
                CamerasModel.Cameras.Add(cvm.Camera);
                MultipleViewsService.TrackerServices.Add(cvm.TrackerService);
            });

            Messenger.Default.Register<RemoveCameraMessage>(this, message =>
            {
                if(SimpleIoc.Default.ContainsCreated<CameraViewModel>(message.Camera.GUID))
                {
                    CameraViewModel cvm = SimpleIoc.Default.GetInstance<CameraViewModel>(message.Camera.GUID);
                    CameraViewModels.Remove(cvm);
                    CamerasModel.Cameras.Remove(cvm.Camera);
                    MultipleViewsService.TrackerServices.Remove(cvm.TrackerService);
                }
            });

            Messenger.Default.Register<AddMotionControllerMessage>(this,
            message =>
            {
                CamerasModel.Controllers.Add(message.MotionController);
            });

            Messenger.Default.Register<RemoveMotionControllerMessage>(this,
            message =>
            {
                CamerasModel.Controllers.Remove(message.MotionController);
            });

            if(IsInDesignMode)
            {
                CamerasModel.Cameras.Add(new CameraViewModel().Camera);
                CamerasModel.Cameras.Add(new CameraViewModel().Camera);
                CamerasModel.Cameras.Add(new CameraViewModel().Camera);
                CamerasModel.Cameras.Add(new CameraViewModel().Camera);
                CamerasModel.Controllers.Add(new MotionControllerModel());
                CamerasModel.Controllers.Add(new MotionControllerModel());
            }
            else
            {
                if (SimpleIoc.Default.GetInstance<SettingsViewModel>().Settings.LoadCamerasOnStartup)
                {
                    AddAvailableCameras();
                }
                if(SimpleIoc.Default.GetInstance<SettingsViewModel>().Settings.Debug)
                {
                    new CameraViewModel();
                    new CameraViewModel();
                    new CameraViewModel();
                    new CameraViewModel();
                }
            }
        }
        void CameraView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (e.OldValue is CameraViewModel)
            {
                //Console.WriteLine("old " + ((CameraViewModel)e.OldValue).Camera.Name);
            }
            if (e.NewValue is CameraViewModel)
            {
                //Console.WriteLine("new " + ((CameraViewModel)e.NewValue).Camera.Name);
                _viewModel = (CameraViewModel)DataContext;

                ApplySelectionButton.Command = ApplySelectionCommand;
                CancelSelectionButton.Command = CancelSelectionCommand;
                CalibrateButton.Command = CalibrateCameraCommand;
            }
        }