private void OnGraphicComplete(object sender, GraphicEventArgs e) { _graphicBuilder.GraphicCancelled -= OnGraphicCancelled; _graphicBuilder.GraphicComplete -= OnGraphicComplete; _graphicBuilder = null; if (_primitiveGraphic != null) { bool boundingBoxTooSmall = false; _primitiveGraphic.CoordinateSystem = CoordinateSystem.Destination; if (_primitiveGraphic.BoundingBox.Width < 50 || _primitiveGraphic.BoundingBox.Height < 50) { boundingBoxTooSmall = true; } _primitiveGraphic.ResetCoordinateSystem(); if (boundingBoxTooSmall) { RemoveDrawShutterGraphic(); base.SelectedPresentationImage.Draw(); } else { GeometricShutter shutter = ConvertToGeometricShutter(); GeometricShuttersGraphic shuttersGraphic = GetGeometricShuttersGraphic((IDicomPresentationImage)base.SelectedPresentationImage, true); DrawableUndoableCommand command = new DrawableUndoableCommand(shuttersGraphic); command.Name = SR.CommandDrawShutter; command.Enqueue(new AddGeometricShutterUndoableCommand(shuttersGraphic, shutter)); command.Execute(); base.ImageViewer.CommandHistory.AddCommand(command); } } }
private void CaptureEndState() { if (!CanPan() || _memorableCommand == null) { return; } _memorableCommand.EndState = GetSelectedImageTransform().CreateMemento(); UndoableCommand applicatorCommand = _toolBehavior.Behavior.SelectedImagePanTool ? null : _applicator.ApplyToLinkedImages(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(this.SelectedPresentationImage); if (!_memorableCommand.EndState.Equals(_memorableCommand.BeginState)) { historyCommand.Enqueue(_memorableCommand); } if (applicatorCommand != null) { historyCommand.Enqueue(applicatorCommand); } if (historyCommand.Count > 0) { historyCommand.Name = SR.CommandPan; this.Context.Viewer.CommandHistory.AddCommand(historyCommand); } _memorableCommand = null; }
private void CaptureEndState() { if (!CanAdjustAlpha() || _memorableCommand == null) { return; } if (this.SelectedLayerOpacityProvider != null) { _memorableCommand.EndState = GetSelectedLayerOpacityManager().CreateMemento(); UndoableCommand applicatorCommand = _applicator.ApplyToLinkedImages(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(this.SelectedPresentationImage); if (!_memorableCommand.EndState.Equals(_memorableCommand.BeginState)) { historyCommand.Enqueue(_memorableCommand); } if (applicatorCommand != null) { historyCommand.Enqueue(applicatorCommand); } if (historyCommand.Count > 0) { historyCommand.Name = SR.CommandAdjustOpacity; this.Context.Viewer.CommandHistory.AddCommand(historyCommand); } } }
/// <summary> /// Helper method to add the operation of an <see cref="ControlGraphic"/> implementing <see cref="IMemorable"/> to the associated command history. /// </summary> /// <typeparam name="T">The derived type of <see cref="ControlGraphic"/>. Must implement <see cref="IMemorable"/>.</typeparam> /// <param name="originator">The <see cref="ControlGraphic"/> that performed the operation.</param> /// <param name="beginState">The memento created by <see cref="IMemorable.CreateMemento"/> before the operation.</param> /// <param name="endState">The memento created by <see cref="IMemorable.CreateMemento"/> after the operation.</param> protected static void AddToCommandHistory <T>(T originator, object beginState, object endState) where T : ControlGraphic, IMemorable { if (originator.ImageViewer == null) { return; } if (beginState == endState) // ensure that both states aren't simultaneously null and that they're not the same states { return; } if (beginState != null && beginState.Equals(endState)) // ensure that beginState isn't equivalent to endState { return; } MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(originator); memorableCommand.BeginState = beginState; memorableCommand.EndState = endState; DrawableUndoableCommand command = new DrawableUndoableCommand(originator); command.Name = originator.CommandName; command.Enqueue(memorableCommand); originator.ImageViewer.CommandHistory.AddCommand(command); }
public void Clear() { if (base.SelectedPresentationImage == null) { return; } if (base.SelectedPresentationImage is IDicomPresentationImage) { IDicomPresentationImage dicomImage = (IDicomPresentationImage)base.SelectedPresentationImage; GeometricShuttersGraphic shuttersGraphic = DrawShutterTool.GetGeometricShuttersGraphic(dicomImage); if (shuttersGraphic == null) { return; } DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(shuttersGraphic); foreach (GeometricShutter shutter in shuttersGraphic.CustomShutters) { historyCommand.Enqueue(new RemoveGeometricShutterUndoableCommand(shuttersGraphic, shutter)); } historyCommand.Execute(); historyCommand.Name = SR.CommandClearCustomShutters; base.Context.Viewer.CommandHistory.AddCommand(historyCommand); Visible = false; } }
public static void SetTileLayout(IImageViewer imageViewer, int rows, int columns) { Platform.CheckForNullReference(imageViewer, "imageViewer"); Platform.CheckArgumentRange(rows, 1, LayoutSettings.MaximumTileRows, "rows"); Platform.CheckArgumentRange(columns, 1, LayoutSettings.MaximumTileColumns, "columns"); IImageBox imageBox = imageViewer.PhysicalWorkspace.SelectedImageBox; if (imageBox == null || imageBox.ParentPhysicalWorkspace.Locked) { return; } var memorableCommand = new MemorableUndoableCommand(imageBox) { BeginState = imageBox.CreateMemento() }; int index = imageBox.TopLeftPresentationImageIndex; imageBox.SetTileGrid(rows, columns); imageBox.TopLeftPresentationImageIndex = index; imageBox.Draw(); imageBox.SelectDefaultTile(); memorableCommand.EndState = imageBox.CreateMemento(); var historyCommand = new DrawableUndoableCommand(imageBox) { Name = SR.CommandLayoutTiles }; historyCommand.Enqueue(memorableCommand); imageViewer.CommandHistory.AddCommand(historyCommand); }
internal static void DeleteAll(IPresentationImage image) { // if any editbox exists on the image, forcibly abort it now if (image.Tile.EditBox != null) { image.Tile.EditBox.Cancel(); } IOverlayGraphicsProvider provider = image as IOverlayGraphicsProvider; if (provider == null) { return; } DrawableUndoableCommand command = new DrawableUndoableCommand(image); foreach (IGraphic graphic in provider.OverlayGraphics) { command.Enqueue(new RemoveGraphicUndoableCommand(graphic)); } if (command.Count == 0) { return; } command.Execute(); command.Name = SR.CommandDeleteAllAnnotations; image.ImageViewer.CommandHistory.AddCommand(command); }
protected void AddGraphic(IPresentationImage image, IControlGraphic graphic, IOverlayGraphicsProvider provider) { _undoableCommand = new DrawableUndoableCommand(image); _undoableCommand.Enqueue(new AddGraphicUndoableCommand(graphic, provider.OverlayGraphics)); _undoableCommand.Name = CreationCommandName; _undoableCommand.Execute(); }
private void CaptureEndState() { if (!CanWindowLevel() || _memorableCommand == null) { return; } if (SelectedVoiLutProvider.VoiLutManager.VoiLut is IBasicVoiLutLinear) { _memorableCommand.EndState = GetSelectedImageVoiLutManager().CreateMemento(); UndoableCommand applicatorCommand = _toolBehavior.Behavior.SelectedImageWindowLevelTool ? 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.CommandWindowLevel; Context.Viewer.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 OnGraphicBuilderCancelled(object sender, GraphicEventArgs e) { _graphicBuilder.GraphicComplete -= OnGraphicBuilderComplete; _graphicBuilder.GraphicCancelled -= OnGraphicBuilderCancelled; _undoableCommand.Unexecute(); _undoableCommand = null; _graphicBuilder = 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 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 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(); }
private void DeleteCurrentPage(object sender, EventArgs args) { if (this.Context.Viewer == null || this.Context.Viewer.SelectedImageBox == null || this.Context.Viewer.SelectedImageBox.DisplaySet == null) { return; } PrintViewImageBox imageBox = this.ImageViewer.SelectedImageBox as PrintViewImageBox; var memorableCommand = new MemorableUndoableCommand(imageBox) { BeginState = CreateMemento() }; var printImageViewer = Context.Viewer as PrintImageViewerComponent; foreach (PrintViewTile tile in imageBox.Tiles) { if (tile.PresentationImage == null) { int number1 = imageBox.TotleImageCount - imageBox.DisplaySet.PresentationImages.Count; if (number1 > 0) { imageBox.TotleImageCount = imageBox.TotleImageCount - 1; } tile.Deselect(); continue; } if (imageBox.DisplaySet.PresentationImages.Contains(tile.PresentationImage)) { if (printImageViewer.SelectPresentationImages.Contains(tile.PresentationImage as PresentationImage)) { var pi = tile.PresentationImage as PresentationImage; pi.Selected = false; printImageViewer.SelectPresentationImages.Remove(pi); } imageBox.DisplaySet.PresentationImages.Remove(tile.PresentationImage); //tile.PresentationImage.Dispose(); tile.PresentationImage = null; tile.Deselect(); } } imageBox.TopLeftPresentationImageIndex = imageBox.TopLeftPresentationImageIndex - imageBox.Tiles.Count; imageBox.Draw(); imageBox.SelectDefaultTile(); memorableCommand.EndState = CreateMemento(); var historyCommand = new DrawableUndoableCommand(imageBox) { Name = SR.CommandPrintPreviewDeleteImage }; historyCommand.Enqueue(memorableCommand); this.Context.Viewer.CommandHistory.AddCommand(historyCommand); PropertyChanged(); }
private void OnGraphicBuilderComplete(object sender, GraphicEventArgs e) { _graphicBuilder.GraphicComplete -= OnGraphicBuilderComplete; _graphicBuilder.GraphicCancelled -= OnGraphicBuilderCancelled; _graphicBuilder.Graphic.ImageViewer.CommandHistory.AddCommand(_undoableCommand); _graphicBuilder.Graphic.Draw(); _undoableCommand = null; this.Active = true;//set the defaut is pan _graphicBuilder = null; }
private void OnGraphicBuilderComplete(object sender, GraphicEventArgs e) { _graphicBuilder.GraphicComplete -= OnGraphicBuilderComplete; _graphicBuilder.GraphicCancelled -= OnGraphicBuilderCancelled; _graphicBuilder.Graphic.ImageViewer.CommandHistory.AddCommand(_undoableCommand); _graphicBuilder.Graphic.Draw(); _undoableCommand = null; _graphicBuilder = null; }
/// <summary> /// Fired when the graphic builder is also done setting text in the graphic, and thus we can decide if we want to unexecute /// the insert or save the command into the history. /// </summary> private void OnGraphicFinalCancelled(object sender, GraphicEventArgs e) { InteractiveTextGraphicBuilder graphicBuilder = sender as InteractiveTextGraphicBuilder; if (graphicBuilder != null) { graphicBuilder.GraphicFinalComplete -= OnGraphicFinalComplete; graphicBuilder.GraphicFinalCancelled -= OnGraphicFinalCancelled; } _undoableCommand.Unexecute(); _undoableCommand = null; }
/// <summary> /// Fired when the graphic builder is also done setting text in the graphic, and thus we can decide if we want to unexecute /// the insert or save the command into the history. /// </summary> private void OnGraphicFinalComplete(object sender, GraphicEventArgs e) { // fired InteractiveTextGraphicBuilder graphicBuilder = sender as InteractiveTextGraphicBuilder; if (graphicBuilder != null) { graphicBuilder.GraphicFinalComplete -= OnGraphicFinalComplete; graphicBuilder.GraphicFinalCancelled -= OnGraphicFinalCancelled; } ImageViewer.CommandHistory.AddCommand(_undoableCommand); _undoableCommand = null; }
public void Delete() { if (SelectedOverlayGraphicsProvider == null || SelectedPresentationImage == null) return; if (!IsGraphicInCollection(SelectedPresentationImage.SelectedGraphic, SelectedOverlayGraphicsProvider.OverlayGraphics)) return; DrawableUndoableCommand command = new DrawableUndoableCommand(SelectedPresentationImage); command.Enqueue(new RemoveGraphicUndoableCommand(SelectedPresentationImage.SelectedGraphic)); command.Execute(); command.Name = SR.CommandDeleteAnnotation; SelectedPresentationImage.ImageViewer.CommandHistory.AddCommand(command); }
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(); }
public override bool Stop(IMouseInformation mouseInformation) { if (_graphicBuilder == null) { return(false); } if (_graphicBuilder.Stop(mouseInformation)) { return(true); } _graphicBuilder = null; _undoableCommand = null; return(false); }
public override bool Stop(IMouseInformation mouseInformation) { if (_graphicBuilder == null) { return(false); } if (_graphicBuilder.Stop(mouseInformation)) { return(true); } _graphicBuilder.Graphic.ImageViewer.CommandHistory.AddCommand(_undoableCommand); _graphicBuilder = null; _undoableCommand = null; return(false); }
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; }
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; }
public void Undoable(string name, Func <bool> action) { IPhysicalWorkspace workspace = Context.Viewer.PhysicalWorkspace; MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(workspace); memorableCommand.BeginState = workspace.CreateMemento(); if (!action()) { return; } memorableCommand.EndState = workspace.CreateMemento(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(workspace); historyCommand.Name = name; historyCommand.Enqueue(memorableCommand); Context.Viewer.CommandHistory.AddCommand(historyCommand); }
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); }
public override bool Stop(IMouseInformation mouseInformation) { if (!Enabled) { return(false); } if (_graphicBuilder != null && _graphicBuilder.Stop(mouseInformation)) { _primitiveGraphic.Draw(); return(true); } if (_graphicBuilder == null && _primitiveGraphic != null) { bool boundingBoxTooSmall = false; _primitiveGraphic.CoordinateSystem = CoordinateSystem.Destination; if (_primitiveGraphic.BoundingBox.Width < 50 || _primitiveGraphic.BoundingBox.Height < 50) { boundingBoxTooSmall = true; } _primitiveGraphic.ResetCoordinateSystem(); if (boundingBoxTooSmall) { RemoveDrawShutterGraphic(); base.SelectedPresentationImage.Draw(); } else { GeometricShutter shutter = ConvertToGeometricShutter(); GeometricShuttersGraphic shuttersGraphic = GetGeometricShuttersGraphic((IDicomPresentationImage)base.SelectedPresentationImage); DrawableUndoableCommand command = new DrawableUndoableCommand(shuttersGraphic); command.Name = SR.CommandDrawShutter; command.Enqueue(new AddGeometricShutterUndoableCommand(shuttersGraphic, shutter)); command.Execute(); base.ImageViewer.CommandHistory.AddCommand(command); } } return(false); }
public void AdvanceDisplaySet(int direction) { if (!Enabled) { return; } IDisplaySet sourceDisplaySet = GetSourceDisplaySet(); if (sourceDisplaySet == null) { return; } IImageBox imageBox = base.Context.Viewer.SelectedImageBox; IImageSet parentImageSet = sourceDisplaySet.ParentImageSet; int sourceDisplaySetIndex = parentImageSet.DisplaySets.IndexOf(sourceDisplaySet); sourceDisplaySetIndex += direction; if (sourceDisplaySetIndex < 0) { sourceDisplaySetIndex = parentImageSet.DisplaySets.Count - 1; } else if (sourceDisplaySetIndex >= parentImageSet.DisplaySets.Count) { sourceDisplaySetIndex = 0; } MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(imageBox); memorableCommand.BeginState = imageBox.CreateMemento(); imageBox.DisplaySet = parentImageSet.DisplaySets[sourceDisplaySetIndex].CreateFreshCopy(); imageBox.Draw(); memorableCommand.EndState = imageBox.CreateMemento(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(imageBox); historyCommand.Enqueue(memorableCommand); base.Context.Viewer.CommandHistory.AddCommand(historyCommand); }
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(); }
public void Delete() { if (SelectedOverlayGraphicsProvider == null || SelectedPresentationImage == null) { return; } if (!IsGraphicInCollection(base.SelectedPresentationImage.SelectedGraphic, SelectedOverlayGraphicsProvider.OverlayGraphics)) { return; } DrawableUndoableCommand command = new DrawableUndoableCommand(base.SelectedPresentationImage); command.Enqueue(new RemoveGraphicUndoableCommand(base.SelectedPresentationImage.SelectedGraphic)); command.Execute(); command.Name = SR.CommandDeleteAnnotation; base.SelectedPresentationImage.ImageViewer.CommandHistory.AddCommand(command); }
public void PrintPreviewPaste() { var imageBox = this.ImageViewer.SelectedImageBox; if (imageBox == null || imageBox.DisplaySet == null || imageBox.SelectedTile == null || selectPresentationImages == null) { return; } var memorableCommand = new MemorableUndoableCommand(imageBox) { BeginState = CreateMemento() }; if (this.Context.Viewer.SelectedPresentationImage == null) { foreach (var selectPresentationImage in selectPresentationImages) { imageBox.DisplaySet.PresentationImages.Add(ImageExporter.ClonePresentationImage(selectPresentationImage)); } } else { int index = imageBox.DisplaySet.PresentationImages.IndexOf(this.Context.Viewer.SelectedPresentationImage); for (int i = selectPresentationImages.Count - 1; i >= 0; i--) { imageBox.DisplaySet.PresentationImages.Insert(index, ImageExporter.ClonePresentationImage(selectPresentationImages[i])); } } imageBox.TopLeftPresentationImageIndex = imageBox.TopLeftPresentationImageIndex; imageBox.Draw(); imageBox.SelectDefaultTile(); memorableCommand.EndState = CreateMemento(); var historyCommand = new DrawableUndoableCommand(imageBox) { Name = SR.CommandPrintPreviewPaste }; historyCommand.Enqueue(memorableCommand); this.Context.Viewer.CommandHistory.AddCommand(historyCommand); PropertyChanged(); }
public void Clear() { if (base.SelectedPresentationImage == null) return; if (base.SelectedPresentationImage is IDicomPresentationImage) { IDicomPresentationImage dicomImage = (IDicomPresentationImage)base.SelectedPresentationImage; GeometricShuttersGraphic shuttersGraphic = DrawShutterTool.GetGeometricShuttersGraphic(dicomImage); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(shuttersGraphic); foreach (GeometricShutter shutter in shuttersGraphic.CustomShutters) historyCommand.Enqueue(new RemoveGeometricShutterUndoableCommand(shuttersGraphic, shutter)); historyCommand.Execute(); historyCommand.Name = SR.CommandClearCustomShutters; base.Context.Viewer.CommandHistory.AddCommand(historyCommand); Visible = false; } }
public override bool Stop(IMouseInformation mouseInformation) { if (!Enabled) return false; if (_graphicBuilder != null && _graphicBuilder.Stop(mouseInformation)) { _primitiveGraphic.Draw(); return true; } if (_graphicBuilder == null && _primitiveGraphic != null) { bool boundingBoxTooSmall = false; _primitiveGraphic.CoordinateSystem = CoordinateSystem.Destination; if (_primitiveGraphic.BoundingBox.Width < 50 || _primitiveGraphic.BoundingBox.Height < 50) boundingBoxTooSmall = true; _primitiveGraphic.ResetCoordinateSystem(); if (boundingBoxTooSmall) { RemoveDrawShutterGraphic(); base.SelectedPresentationImage.Draw(); } else { GeometricShutter shutter = ConvertToGeometricShutter(); GeometricShuttersGraphic shuttersGraphic = GetGeometricShuttersGraphic((IDicomPresentationImage) base.SelectedPresentationImage); DrawableUndoableCommand command = new DrawableUndoableCommand(shuttersGraphic); command.Name = SR.CommandDrawShutter; command.Enqueue(new AddGeometricShutterUndoableCommand(shuttersGraphic, shutter)); command.Execute(); base.ImageViewer.CommandHistory.AddCommand(command); } } return false; }
private void OnGraphicComplete(object sender, GraphicEventArgs e) { _graphicBuilder.GraphicCancelled -= OnGraphicCancelled; _graphicBuilder.GraphicComplete -= OnGraphicComplete; _graphicBuilder = null; if (_primitiveGraphic != null) { bool boundingBoxTooSmall = false; _primitiveGraphic.CoordinateSystem = CoordinateSystem.Destination; if (_primitiveGraphic.BoundingBox.Width < 50 || _primitiveGraphic.BoundingBox.Height < 50) boundingBoxTooSmall = true; _primitiveGraphic.ResetCoordinateSystem(); if (boundingBoxTooSmall) { RemoveDrawShutterGraphic(); base.SelectedPresentationImage.Draw(); } else { GeometricShutter shutter = ConvertToGeometricShutter(); GeometricShuttersGraphic shuttersGraphic = GetGeometricShuttersGraphic((IDicomPresentationImage) base.SelectedPresentationImage, true); DrawableUndoableCommand command = new DrawableUndoableCommand(shuttersGraphic); command.Name = SR.CommandDrawShutter; command.Enqueue(new AddGeometricShutterUndoableCommand(shuttersGraphic, shutter)); command.Execute(); base.ImageViewer.CommandHistory.AddCommand(command); } } }
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 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 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; }
public override bool Stop(IMouseInformation mouseInformation) { if (_graphicBuilder == null) return false; if (_graphicBuilder.Stop(mouseInformation)) return true; _graphicBuilder.Graphic.ImageViewer.CommandHistory.AddCommand(_undoableCommand); _graphicBuilder = null; _undoableCommand = null; return false; }
private void OnEditBoxComplete(object sender, EventArgs e) { bool removeFromParent = false; if (_currentCalloutEditBox != null) { removeFromParent = _deleteOnEmpty && string.IsNullOrEmpty(_currentCalloutEditBox.LastAcceptedValue); if (!removeFromParent) { object state = this.CreateMemento(); this.Text = _currentCalloutEditBox.LastAcceptedValue; AddToCommandHistory(this, state, this.CreateMemento()); this.Draw(); } } EndEdit(); if (removeFromParent && base.ImageViewer != null) { // find the highest-level control graphic IGraphic graphic = this; while (graphic != null && graphic.ParentGraphic is IControlGraphic) graphic = graphic.ParentGraphic; if (graphic != null && graphic.ParentPresentationImage != null) { IImageViewer imageViewer = base.ImageViewer; DrawableUndoableCommand command = new DrawableUndoableCommand(graphic.ParentPresentationImage); command.Name = SR.CommandDelete; command.Enqueue(new RemoveGraphicUndoableCommand(graphic)); command.Execute(); imageViewer.CommandHistory.AddCommand(command); } } }
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 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; }
public override bool Stop(IMouseInformation mouseInformation) { if (_graphicBuilder == null) return false; if (_graphicBuilder.Stop(mouseInformation)) return true; _graphicBuilder = null; _undoableCommand = null; return false; }
private void CaptureEndState() { if (!CanAdjustAlpha() || _memorableCommand == null) return; if (this.SelectedLayerOpacityProvider != null) { _memorableCommand.EndState = GetSelectedLayerOpacityManager().CreateMemento(); UndoableCommand applicatorCommand = _applicator.ApplyToLinkedImages(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(this.SelectedPresentationImage); if (!_memorableCommand.EndState.Equals(_memorableCommand.BeginState)) historyCommand.Enqueue(_memorableCommand); if (applicatorCommand != null) historyCommand.Enqueue(applicatorCommand); if (historyCommand.Count > 0) { historyCommand.Name = SR.CommandAdjustOpacity; this.Context.Viewer.CommandHistory.AddCommand(historyCommand); } } }
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); }
public void Delete() { IGraphic graphic = Context.Graphic; if (graphic == null) return; IPresentationImage image = graphic.ParentPresentationImage; if (image == null) return; DrawableUndoableCommand command = new DrawableUndoableCommand(graphic.ParentPresentationImage); command.Enqueue(new RemoveGraphicUndoableCommand(graphic)); command.Execute(); command.Name = SR.CommandDeleteAnnotation; image.ImageViewer.CommandHistory.AddCommand(command); }
private void CaptureEndState() { if (!CanWindowLevel() || _memorableCommand == null) return; if (SelectedVoiLutProvider.VoiLutManager.VoiLut is IBasicVoiLutLinear) { _memorableCommand.EndState = GetSelectedImageVoiLutManager().CreateMemento(); UndoableCommand applicatorCommand = _toolBehavior.Behavior.SelectedImageWindowLevelTool ? 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.CommandWindowLevel; Context.Viewer.CommandHistory.AddCommand(historyCommand); } } }
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); } }
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); }
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 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 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(); }
internal static void DeleteAll(IPresentationImage image) { // if any editbox exists on the image, forcibly abort it now if (image.Tile.EditBox != null) image.Tile.EditBox.Cancel(); IOverlayGraphicsProvider provider = image as IOverlayGraphicsProvider; if (provider == null) return; DrawableUndoableCommand command = new DrawableUndoableCommand(image); foreach (IGraphic graphic in provider.OverlayGraphics) command.Enqueue(new RemoveGraphicUndoableCommand(graphic)); if (command.Count == 0) return; command.Execute(); command.Name = SR.CommandDeleteAllAnnotations; image.ImageViewer.CommandHistory.AddCommand(command); }