private void SynchronizeImagePosition(Dictionary <String, Object> parameters) { if ((int)parameters["PresenterID"] == ViewModelID) { return; } Dictionary <String, Object> args = new Dictionary <String, Object>(parameters); args["DisplayedImage"] = DisplayedImage; args["Position"] = ImagePosition; args["PresenterID"] = ViewModelID; PanImage pi = new PanImage(); pi.AffectImage(args); }
public ImagePresenterViewModel(ObservableCollection <Image> image, int viewModelID, Tools tool, int maxWindows) { switch (tool) { case Tools.None: break; case Tools.RegionSelection: Tool = new CreateRegion(); break; case Tools.PixelInformations: Tool = new PixelPicker(); break; case Tools.RegionTransformation: break; case Tools.ImagePan: Tool = new PanImage(); break; case Tools.Rotate: Tool = new Rotate(); break; default: break; } ViewModelID = viewModelID; MaxWindows = maxWindows; _imageList = new ObservableCollection <Image>(); _imageList = image; ImageIndex = 0; DisplayedImage = _imageList[_imageIndex]; IsSynchronized = true; Scale = 1; SubscriptionToken token; token = _aggregator.GetEvent <SerializeOutputEvent>().Subscribe(SerializeOutputFromPresenters); _subscriptionTokens.Add(typeof(SerializeOutputEvent), token); token = _aggregator.GetEvent <RotateImageEvent>().Subscribe(RotateImage); _subscriptionTokens.Add(typeof(RotateImageEvent), token); token = _aggregator.GetEvent <SynchronizationEvent>().Subscribe(i => { if (ViewModelID == i) { IsSynchronized = !IsSynchronized; } }); _subscriptionTokens.Add(typeof(SynchronizationEvent), token); token = _aggregator.GetEvent <SendDisplayedImage>().Subscribe(item => { if ((item.PresenterID == ViewModelID || (item.DoReset == true && item.IsSynchronized && IsSynchronized)) && item.Image != null) { ImagePosition = item.Image.Position; } else if (item.IsSynchronized == true && IsSynchronized && item.DoReset == false) { ImagePosition = new Thickness(ImagePosition.Left + item.OffsetX, ImagePosition.Top + item.OffsetY, -(ImagePosition.Left + item.OffsetX), -(ImagePosition.Top + item.OffsetY)); } if (item.DoProcessing) { CalculateRegionProperties(); } }); _subscriptionTokens.Add(typeof(SendDisplayedImage), token); token = _aggregator.GetEvent <SendToolEvent>().Subscribe(item => { Tool = item; }); _subscriptionTokens.Add(typeof(SendToolEvent), token); token = _aggregator.GetEvent <SendRegionNameEvent>().Subscribe(SaveRegion); _subscriptionTokens.Add(typeof(SendRegionNameEvent), token); token = _aggregator.GetEvent <LoadRegionEvent>().Subscribe(region => { if (region.PresenterID > MaxWindows) { region.PresenterID = DisplayImageWindowViewModel.ImageCounter; } if (region.PresenterID != ViewModelID) { return; } if (_imageList != region.ImageList) { _imageList = region.ImageList; } DisplayedImage = region.ImageList.First(x => x == region.AttachedImage); RegionLocation = new Thickness(region.Position.X * 96.0 / region.DpiX, region.Position.Y * 96.0 / region.DpiY, 0, 0); RegionWidth = (int)(region.Size.Width * 96.0 / region.DpiX); RegionHeight = (int)(region.Size.Height * 96.0 / region.DpiY); ImageIndex = region.ImageIndex; Scale = region.Zoom; ImagePosition = region.ImagePosition; if (IsSynchronized) { SynchronizeRegions sr = new SynchronizeRegions(); sr.PresenterID = ViewModelID; sr.Position = RegionLocation; sr.Width = RegionWidth; sr.Height = RegionHeight; sr.DoProcessing = true; sr.Zoom = Scale; _aggregator.GetEvent <SynchronizeRegions>().Publish(sr); } CalculateRegionProperties(); }); _subscriptionTokens.Add(typeof(LoadRegionEvent), token); token = _aggregator.GetEvent <SendImageList>().Subscribe(item => { try { if (item.Count != 0) { if (!item.Any(x => x == _imageList)) { _imageList = item[0]; ImageIndex = 0; DisplayedImage = _imageList[0]; } } else { DisplayedImage = null; _imageList = null; } } catch (Exception) { } }); _subscriptionTokens.Add(typeof(SendImageList), token); token = _aggregator.GetEvent <ResetRegionsEvent>().Subscribe(() => { RegionHeight = 0; RegionWidth = 0; RegionLocation = new Thickness(0, 0, 0, 0); }); _subscriptionTokens.Add(typeof(ResetRegionsEvent), token); ImageClickCommand = new GalaSoft.MvvmLight.Command.RelayCommand <RoutedEventArgs>(ImageClickExecute); LeftArrowCommand = new RelayCommand(PreviousImage); RightArrowCommand = new RelayCommand(NextImage); SaveRegionCommand = new RelayCommand(OpenSaveRegionWindow); SerializeOutputFromListCommand = new RelayCommand(SerializeOutputFromList); EscapeCommand = new RelayCommand(EscapeClicked); SelectAllCommand = new RelayCommand(SelectAll); ResetPositionCommand = new RelayCommand(ResetPosition); ResetZoomCommand = new RelayCommand(ResetZoom); MouseLeftClickCommand = new GalaSoft.MvvmLight.Command.RelayCommand <RoutedEventArgs>(MouseLeftClick); MouseMoveCommand = new GalaSoft.MvvmLight.Command.RelayCommand <RoutedEventArgs>(MouseMove); MouseOverCommand = new GalaSoft.MvvmLight.Command.RelayCommand <RoutedEventArgs>(MouseEnter); MouseWheelCommand = new GalaSoft.MvvmLight.Command.RelayCommand <MouseWheelEventArgs>(MouseWheel); Filter_BrightnessCommand = new RelayCommand(FilterChoose); Filter_ContrastCommand = new RelayCommand(FilterChoose); Filter_GreyScaleCommand = new RelayCommand(FilterChoose); Filter_NegativeCommand = new RelayCommand(FilterChoose); Filter_SepiaCommand = new RelayCommand(FilterChoose); Filter_ResetCommand = new RelayCommand(FilterChoose); }