private static void Execute(IImageBox imageBox, object unexplodeMemento) { MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(imageBox); memorableCommand.BeginState = imageBox.CreateMemento(); IDisplaySet displaySet = imageBox.DisplaySet; IPresentationImage selectedImage; if (imageBox.SelectedTile != null) selectedImage = imageBox.SelectedTile.PresentationImage; else selectedImage = imageBox.TopLeftPresentationImage; imageBox.SetMemento(unexplodeMemento); //TODO (architecture): this wouldn't be necessary if we had a SetImageBoxGrid(imageBox[,]). //This stuff with mementos is actually a hacky workaround. bool locked = imageBox.DisplaySetLocked; imageBox.DisplaySetLocked = false; imageBox.DisplaySet = displaySet; imageBox.DisplaySetLocked = locked; if (selectedImage != null) imageBox.TopLeftPresentationImage = selectedImage; imageBox.Draw(); imageBox.SelectDefaultTile(); memorableCommand.EndState = imageBox.CreateMemento(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(imageBox); historyCommand.Name = SR.CommandExplodeTile; historyCommand.Enqueue(memorableCommand); imageBox.ParentPhysicalWorkspace.ImageViewer.CommandHistory.AddCommand(historyCommand); }
private void CaptureBeginState() { if (!CanAdjustAlpha()) return; ILayerOpacityManager originator = GetSelectedLayerOpacityManager(); _applicator = new ImageOperationApplicator(this.SelectedPresentationImage, _operation); _memorableCommand = new MemorableUndoableCommand(originator); _memorableCommand.BeginState = originator.CreateMemento(); }
public void ResetAll() { DrawableUndoableCommand command = new DrawableUndoableCommand(this.ImageViewer.PhysicalWorkspace); command.Name = SR.CommandMprReset; MemorableUndoableCommand toolGroupStateCommand = new MemorableUndoableCommand(this.ToolGroupState); toolGroupStateCommand.BeginState = this.ToolGroupState.CreateMemento(); toolGroupStateCommand.EndState = this.InitialToolGroupStateMemento; command.Enqueue(toolGroupStateCommand); command.Execute(); if (this.ImageViewer.CommandHistory != null) this.ImageViewer.CommandHistory.AddCommand(command); this.CanReset = false; }
internal static void AssignDisplaySetToImageBox(IImageBox imageBox, IDisplaySet displaySet) { MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(imageBox); memorableCommand.BeginState = imageBox.CreateMemento(); // always create a 'fresh copy' to show in the image box. We never want to show // the 'originals' (e.g. the ones in IImageSet.DisplaySets) because we want them // to remain clean and unaltered - consider them to be templates for what actually // gets shown. imageBox.DisplaySet = displaySet.CreateFreshCopy(); imageBox.Draw(); //this.ImageViewer.SelectedImageBox[0, 0].Select(); memorableCommand.EndState = imageBox.CreateMemento(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(imageBox); historyCommand.Enqueue(memorableCommand); imageBox.ImageViewer.CommandHistory.AddCommand(historyCommand); }
private bool CaptureEndState() { if (_memorableCommand == null || _currentImageBox == null) { _currentImageBox = null; return false; } bool commandAdded = false; // If nothing's changed then just return if (_initialPresentationImageIndex != _currentImageBox.SelectedTile.PresentationImageIndex) { // Capture state after stack _memorableCommand.EndState = _currentImageBox.CreateMemento(); if (!_memorableCommand.EndState.Equals(_memorableCommand.BeginState)) { var historyCommand = new DrawableUndoableCommand(_currentImageBox) {Name = SR.CommandStack}; historyCommand.Enqueue(_memorableCommand); Context.Viewer.CommandHistory.AddCommand(historyCommand); commandAdded = true; } } _memorableCommand = null; _currentImageBox = null; return commandAdded; }
private void CaptureBeginState(IImageBox imageBox) { _memorableCommand = new MemorableUndoableCommand(imageBox) {BeginState = imageBox.CreateMemento()}; // Capture state before stack _currentImageBox = imageBox; _initialPresentationImageIndex = imageBox.SelectedTile.PresentationImageIndex; }
private void CaptureEndState() { if (!CanRotate() || _memorableCommand == null) return; _memorableCommand.EndState = GetSelectedImageTransform().CreateMemento(); UndoableCommand applicatorCommand = _toolBehavior.Behavior.SelectedImageRotate3DTool ? null : _applicator.ApplyToLinkedImages(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(SelectedPresentationImage); if (!_memorableCommand.EndState.Equals(_memorableCommand.BeginState)) historyCommand.Enqueue(_memorableCommand); if (applicatorCommand != null) historyCommand.Enqueue(applicatorCommand); if (historyCommand.Count > 0) { historyCommand.Name = SR.CommandRotate3D; Context.Viewer.CommandHistory.AddCommand(historyCommand); } _memorableCommand = null; }
private void CaptureBeginState() { if (!CanRotate()) return; _applicator = new ImageOperationApplicator(SelectedPresentationImage, _operation); var originator = GetSelectedImageTransform(); _memorableCommand = new MemorableUndoableCommand(originator); _memorableCommand.BeginState = originator.CreateMemento(); }
private void UnexplodeImageBoxes() { if (!CanUnexplodeImageBox(ImageViewer.SelectedImageBox)) return; IPhysicalWorkspace workspace = ImageViewer.SelectedImageBox.ParentPhysicalWorkspace; Dictionary<IImageBox, object> imageBoxMementoDictionary = new Dictionary<IImageBox, object>(); foreach(IImageBox imageBox in workspace.ImageBoxes) { imageBoxMementoDictionary.Add(imageBox, imageBox.CreateMemento()); } Dictionary<IImageBox, IImageBox> oldMap = oldImageBoxMap; MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(workspace); memorableCommand.BeginState = workspace.CreateMemento(); workspace.SetMemento(_unexplodeMemento); if(0 != oldMap.Count) { foreach (IImageBox box in workspace.ImageBoxes) { //Keep the state of the image box the same. if (oldMap.ContainsKey(box)) { box.SetMemento(imageBoxMementoDictionary[oldMap[box]]); } } } workspace.Draw(); memorableCommand.EndState = workspace.CreateMemento(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(workspace); historyCommand.Name = SR.CommandSurveyExplode; historyCommand.Enqueue(memorableCommand); base.ImageViewer.CommandHistory.AddCommand(historyCommand); CancelExplodeMode(); OnCheckedChanged(); UpdateEnabled(); }
protected override void OnDragDrop(DragEventArgs drgevent) { _tile.Select(); MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(_tile.ParentImageBox); memorableCommand.BeginState = _tile.ParentImageBox.CreateMemento(); IDisplaySet displaySet = (IDisplaySet) drgevent.Data.GetData(typeof (DisplaySet)); _tile.ParentImageBox.DisplaySet = displaySet.CreateFreshCopy(); _tile.ParentImageBox.Draw(); memorableCommand.EndState = _tile.ParentImageBox.CreateMemento(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(_tile.ParentImageBox); historyCommand.Enqueue(memorableCommand); _tile.ImageViewer.CommandHistory.AddCommand(historyCommand); base.OnDragDrop(drgevent); }
public MemorableCommandInfo(MemorableUndoableCommand command) : base(command) { _originator = _rfOriginatorField.GetValue(command) as IMemorable; _beginState = command.BeginState; _endState = command.EndState; }
protected override void Dispose(bool disposing) { _memorableCommand = null; _applicator = null; base.Dispose(disposing); }
private void EndCaptureUndo() { if (_imageBoxCommand != null) { _imageBoxCommand.EndState = _imageBox.CreateMemento(); if (!_imageBoxCommand.BeginState.Equals(_imageBoxCommand.EndState)) { _historyCommand.Name = SR.CommandNameStackImageScroller; _imageBox.ImageViewer.CommandHistory.AddCommand(_historyCommand); } } _imageBoxCommand = null; _historyCommand = null; }
private void BeginCaptureUndo() { _historyCommand = new CompositeUndoableCommand(); DrawableUndoableCommand drawableUndoableCommand = new DrawableUndoableCommand(_imageBox); _imageBoxCommand = new MemorableUndoableCommand(_imageBox); _imageBoxCommand.BeginState = _imageBox.CreateMemento(); drawableUndoableCommand.Enqueue(_imageBoxCommand); _historyCommand.Enqueue(drawableUndoableCommand); }
private void OnGraphicBuilderDone(object sender, GraphicEventArgs e) { if (base.ImageViewer.CommandHistory != null) { DrawableUndoableCommand compositeCommand = new DrawableUndoableCommand(this.ImageViewer.PhysicalWorkspace); compositeCommand.Name = SR.CommandMprReslice; MemorableUndoableCommand toolGroupStateCommand = new MemorableUndoableCommand(_resliceToolGroup.ToolGroupState); toolGroupStateCommand.BeginState = _originalResliceToolsState; toolGroupStateCommand.EndState = _resliceToolGroup.ToolGroupState.CreateMemento(); compositeCommand.Enqueue(toolGroupStateCommand); base.ImageViewer.CommandHistory.AddCommand(compositeCommand); } _originalResliceToolsState = null; RemoveGraphicBuilder(); _lastTopLeftPresentationImageIndex = this.SliceImageBox.TopLeftPresentationImageIndex; }
private void Sort(ImageComparerList.Item item) { IImageBox imageBox = ImageViewer.SelectedImageBox; IDisplaySet displaySet; if (imageBox == null || (displaySet = ImageViewer.SelectedImageBox.DisplaySet) == null) return; if (displaySet.PresentationImages.Count == 0) return; //try to keep the top-left image the same. IPresentationImage topLeftImage = imageBox.TopLeftPresentationImage; var command = new MemorableUndoableCommand(imageBox) {BeginState = imageBox.CreateMemento()}; displaySet.PresentationImages.Sort(item.Comparer); imageBox.TopLeftPresentationImage = topLeftImage; imageBox.Draw(); command.EndState = imageBox.CreateMemento(); if (!command.BeginState.Equals(command.EndState)) { var historyCommand = new DrawableUndoableCommand(imageBox) {Name = SR.CommandSortImages}; historyCommand.Enqueue(command); Context.Viewer.CommandHistory.AddCommand(historyCommand); } }
private void OnControlGraphicUndoableOperationStop(object sender, EventArgs e) { if (base.ImageViewer.CommandHistory != null) { DrawableUndoableCommand compositeCommand = new DrawableUndoableCommand(this.ImageViewer.PhysicalWorkspace); compositeCommand.Name = ((ControlGraphic) sender).CommandName; MemorableUndoableCommand toolGroupStateCommand = new MemorableUndoableCommand(this); toolGroupStateCommand.BeginState = _controlGraphicBeginState; toolGroupStateCommand.EndState = this.CreateMemento(); compositeCommand.Enqueue(toolGroupStateCommand); base.ImageViewer.CommandHistory.AddCommand(compositeCommand); } _controlGraphicBeginState = null; }
private void ExplodeImageBox() { IImageBox imageBox = ImageViewer.SelectedImageBox; if (!CanExplodeImageBox(imageBox)) return; IPhysicalWorkspace workspace = imageBox.ParentPhysicalWorkspace; MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(workspace); memorableCommand.BeginState = workspace.CreateMemento(); _imageBoxesObserver.SuppressChangedEvent = true; //set this here so checked will be correct. _unexplodeMemento = memorableCommand.BeginState; _oldImageBox = imageBox; IDisplaySet displaySet = _oldImageBox.DisplaySet; IPresentationImage selectedImage = _oldImageBox.SelectedTile.PresentationImage; object imageBoxMemento = _oldImageBox.CreateMemento(); workspace.SetImageBoxGrid(1, 1); IImageBox newImageBox = workspace.ImageBoxes[0]; newImageBox.SetMemento(imageBoxMemento); //TODO (architecture): this wouldn't be necessary if we had a SetImageBoxGrid(imageBox[,]). //This stuff with mementos is actually a hacky workaround. bool locked = newImageBox.DisplaySetLocked; newImageBox.DisplaySetLocked = false; newImageBox.DisplaySet = displaySet; newImageBox.TopLeftPresentationImage = selectedImage; newImageBox.DisplaySetLocked = locked; _imageBoxesObserver.SuppressChangedEvent = false; workspace.Draw(); workspace.SelectDefaultImageBox(); memorableCommand.EndState = workspace.CreateMemento(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(workspace); historyCommand.Name = SR.CommandSurveyExplode; historyCommand.Enqueue(memorableCommand); base.ImageViewer.CommandHistory.AddCommand(historyCommand); OnCheckedChanged(); UpdateEnabled(); }
private void ExplodeSelectedTile(IImageBox imageBox) { MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(imageBox); memorableCommand.BeginState = imageBox.CreateMemento(); //set this here so checked will be correct. object unexplodeMemento = memorableCommand.BeginState; _unexplodeCommands[imageBox] = new UnexplodeTileCommand(imageBox, unexplodeMemento, RemoveUnexplodeCommand); IDisplaySet displaySet = imageBox.DisplaySet; IPresentationImage selectedImage = imageBox.SelectedTile.PresentationImage; imageBox.SetTileGrid(1, 1); //TODO (architecture): this wouldn't be necessary if we had a SetImageBoxGrid(imageBox[,]). //This stuff with mementos is actually a hacky workaround. bool locked = imageBox.DisplaySetLocked; imageBox.DisplaySetLocked = false; imageBox.DisplaySet = displaySet; imageBox.DisplaySetLocked = locked; imageBox.TopLeftPresentationImage = selectedImage; memorableCommand.EndState = imageBox.CreateMemento(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(imageBox); historyCommand.Name = SR.CommandExplodeTile; historyCommand.Enqueue(memorableCommand); imageBox.ParentPhysicalWorkspace.ImageViewer.CommandHistory.AddCommand(historyCommand); imageBox.Draw(); imageBox.SelectDefaultTile(); }
private void UnexplodeImageBox() { IImageBox imageBox = ImageViewer.SelectedImageBox; if (!CanUnexplodeImageBox(imageBox)) return; object imageBoxMemento = imageBox.CreateMemento(); IPhysicalWorkspace workspace = imageBox.ParentPhysicalWorkspace; MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(workspace); memorableCommand.BeginState = workspace.CreateMemento(); IImageBox oldImageBox = _oldImageBox; workspace.SetMemento(_unexplodeMemento); foreach (IImageBox box in workspace.ImageBoxes) { //Keep the state of the image box the same. if (box == oldImageBox) { box.SetMemento(imageBoxMemento); break; } } workspace.Draw(); memorableCommand.EndState = workspace.CreateMemento(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(workspace); historyCommand.Name = SR.CommandSurveyExplode; historyCommand.Enqueue(memorableCommand); base.ImageViewer.CommandHistory.AddCommand(historyCommand); CancelExplodeMode(); OnCheckedChanged(); UpdateEnabled(); }
private void CaptureBeginState() { if (!CanWindowLevel()) return; IVoiLutManager originator = GetSelectedImageVoiLutManager(); _applicator = new ImageOperationApplicator(SelectedPresentationImage, _operation); _memorableCommand = new MemorableUndoableCommand(originator); _memorableCommand.BeginState = originator.CreateMemento(); }
private void ExplodeImageBoxes() { if (0 == imageBoxHistory.Count || !CanExplodeImageBox(ImageViewer.SelectedImageBox)) { return; } IPhysicalWorkspace workspace = ImageViewer.SelectedImageBox.ParentPhysicalWorkspace; MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(workspace); memorableCommand.BeginState = workspace.CreateMemento(); _imageBoxesObserver.SuppressChangedEvent = true; //set this here so checked will be correct. _unexplodeMemento = memorableCommand.BeginState; List<IImageBox> explodeImageBoxes = new List<IImageBox>(imageBoxHistory.Skip(imageBoxHistory.Count - WorkspaceScreenCount())); explodeImageBoxes.Reverse(); List<object> mementoList = new List<object>(); foreach (IImageBox imageBox in explodeImageBoxes) { mementoList.Add(imageBox.CreateMemento()); } workspace.SetImageBoxGrid(1, explodeImageBoxes.Count); int i = 0; foreach (IImageBox imageBox in explodeImageBoxes) { IImageBox newImageBox = workspace.ImageBoxes[i]; oldImageBoxMap.Add(imageBox, newImageBox); newImageBox.SetMemento(mementoList[i]); i++; } _imageBoxesObserver.SuppressChangedEvent = false; workspace.Draw(); workspace.SelectDefaultImageBox(); memorableCommand.EndState = workspace.CreateMemento(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(workspace); historyCommand.Name = SR.CommandSurveyExplode; historyCommand.Enqueue(memorableCommand); base.ImageViewer.CommandHistory.AddCommand(historyCommand); OnCheckedChanged(); UpdateEnabled(); }