public MainWindowViewModel()
        {
            _modelCore   = new ModelCore();
            _angleLogger = new AngleLogger(_modelCore);

            //描画とFPSの表示設定
            var drawer = new KinectBodyDrawer(_modelCore.KinectConnector);

            ImageSource = drawer.ImageSource;

            var timerForFps = new DispatcherTimer();

            timerForFps.Interval = TimeSpan.FromMilliseconds(100.0);
            timerForFps.Tick    += (_, __) =>
            {
                FpsFrameArrived = _modelCore.FpsFrameArrived;
                FpsDataSend     = _modelCore.FpsDataSend;
            };

            //イベントとコマンド設定
            SubscribeToModelEvents(_modelCore);
            SendDataChangeToModel(_modelCore);

            ConnectToServerCommand      = new RelayCommand(() => _modelCore.AngleDataSender.Connect(IPAddress, Port));
            DisconnectFromServerCommand = new RelayCommand(() => _modelCore.AngleDataSender.Close());

            CloseWindowCommand = new RelayCommand(() =>
            {
                _modelCore.Dispose();
                _angleLogger.Dispose();
                timerForFps.Stop();
            });

            timerForFps.Start();
        }
        public MainWindowViewModel()
        {
            _modelCore = new ModelCore();
            _angleLogger = new AngleLogger(_modelCore);

            //描画とFPSの表示設定
            var drawer = new KinectBodyDrawer(_modelCore.KinectConnector);
            ImageSource = drawer.ImageSource;

            var timerForFps = new DispatcherTimer();
            timerForFps.Interval = TimeSpan.FromMilliseconds(100.0);
            timerForFps.Tick += (_, __) =>
            {
                FpsFrameArrived = _modelCore.FpsFrameArrived;
                FpsDataSend = _modelCore.FpsDataSend;
            };

            //イベントとコマンド設定
            SubscribeToModelEvents(_modelCore);
            SendDataChangeToModel(_modelCore);

            ConnectToServerCommand = new RelayCommand(() => _modelCore.AngleDataSender.Connect(IPAddress, Port));
            DisconnectFromServerCommand = new RelayCommand(() => _modelCore.AngleDataSender.Close());

            CloseWindowCommand = new RelayCommand(() =>
            {
                _modelCore.Dispose();
                _angleLogger.Dispose();
                timerForFps.Stop();
            });

            timerForFps.Start();
        }
        private void SubscribeToModelEvents(ModelCore model)
        {
            EventHandler <ExceptionMessageEventArgs> eHandler = (_, e) =>
                                                                MessageBox.Show(e.Message, CaptionForErrorMessageBox, MessageBoxButton.OK, MessageBoxImage.Error);

            model.AngleDataSender.IsConnectedChanged += (_, e) => IsServerConnected = e.IsConnected;
            model.AngleDataSender.FailedToConnect    += eHandler;
            model.AngleDataSender.ConnectionDisabled += eHandler;

            model.KinectConnector.IsAvailableChanged += (_, e) => IsKinectConnected = e.IsAvailable;
            model.KinectConnector.BodyUpdated        += (_, e) => SetVectorData(e.Body);
            IsKinectConnected = model.KinectConnector.IsKinectSensorAvailable;
        }
 //Viewから飛んできた変更をそのままモデルに書き込む
 private void SendDataChangeToModel(ModelCore model)
 {
     this.PropertyChanged += (_, e) =>
     {
         if (e.PropertyName == nameof(IsBodyIndexFixed))
         {
             model.KinectConnector.IsBodyIndexFixed = IsBodyIndexFixed;
         }
         else if (e.PropertyName == nameof(FixedBodyIndex))
         {
             model.KinectConnector.FixedBodyIndex = FixedBodyIndex;
         }
     };
 }
예제 #5
0
 public AngleLogger(ModelCore core)
 {
     _modelCore = core;
 }
예제 #6
0
 public AngleLogger(ModelCore core)
 {
     _modelCore = core;
 }
        private void SubscribeToModelEvents(ModelCore model)
        {
            EventHandler<ExceptionMessageEventArgs> eHandler = (_, e) =>
                MessageBox.Show(e.Message, CaptionForErrorMessageBox, MessageBoxButton.OK, MessageBoxImage.Error);

            model.AngleDataSender.IsConnectedChanged += (_, e) => IsServerConnected = e.IsConnected;
            model.AngleDataSender.FailedToConnect += eHandler;
            model.AngleDataSender.ConnectionDisabled += eHandler;

            model.KinectConnector.IsAvailableChanged += (_, e) => IsKinectConnected = e.IsAvailable;
            model.KinectConnector.BodyUpdated += (_, e) => SetVectorData(e.Body);
            IsKinectConnected = model.KinectConnector.IsKinectSensorAvailable;
        }
 //Viewから飛んできた変更をそのままモデルに書き込む
 private void SendDataChangeToModel(ModelCore model)
 {
     this.PropertyChanged += (_, e) =>
     {
         if(e.PropertyName == nameof(IsBodyIndexFixed))
         {
             model.KinectConnector.IsBodyIndexFixed = IsBodyIndexFixed;
         }
         else if(e.PropertyName == nameof(FixedBodyIndex))
         {
             model.KinectConnector.FixedBodyIndex = FixedBodyIndex;
         }
     };
 }