/// <summary> /// Fills <see cref="IPhysicalWorkspace.ImageBoxes"/> with <see cref="IDisplaySet"/>s. /// </summary> /// <remarks> /// <para> /// By default, <see cref="IPhysicalWorkspace.ImageBoxes"/> is filled starting with the first /// <see cref="IImageSet"/>'s <see cref="IDisplaySet"/>, and continuing until there /// are no empty <see cref="IImageBox"/>es or all <see cref="IDisplaySet"/>s have been assigned to an <see cref="IImageBox"/>. /// </para> /// <para> /// Override this method to change how <see cref="IDisplaySet"/>s are assigned to <see cref="IPhysicalWorkspace.ImageBoxes"/>. /// </para> /// </remarks> protected virtual void FillPhysicalWorkspace() { IPhysicalWorkspace physicalWorkspace = ImageViewer.PhysicalWorkspace; ILogicalWorkspace logicalWorkspace = ImageViewer.LogicalWorkspace; if (logicalWorkspace.ImageSets.Count == 0) { return; } int imageSetIndex = 0; int displaySetIndex = 0; foreach (IImageBox imageBox in physicalWorkspace.ImageBoxes) { if (displaySetIndex == logicalWorkspace.ImageSets[imageSetIndex].DisplaySets.Count) { imageSetIndex++; displaySetIndex = 0; if (imageSetIndex == logicalWorkspace.ImageSets.Count) { break; } } imageBox.DisplaySet = logicalWorkspace.ImageSets[imageSetIndex].DisplaySets[displaySetIndex].CreateFreshCopy(); displaySetIndex++; } }
public void ApplyLayout(IImageViewer viewer, AppliedWorkspace layout) { if (layout.DisplaySets.Count != layout.WorkspaceLayout.Rows * layout.WorkspaceLayout.Columns) { throw new ArgumentException(string.Format(SR.MessageAmountOfImageBoxesMismatch, layout.DisplaySets.Count, layout.WorkspaceLayout.Rows, layout.WorkspaceLayout.Columns, layout.WorkspaceLayout.Name)); } IPhysicalWorkspace workspace = viewer.PhysicalWorkspace; workspace.SetImageBoxGrid(layout.WorkspaceLayout.Rows, layout.WorkspaceLayout.Columns); var imageBoxIndex = 0; foreach (var displaySetLayout in layout.DisplaySets) { var imageBox = workspace.ImageBoxes[imageBoxIndex]; imageBox.SetTileGrid( displaySetLayout.Item1.TileRows, displaySetLayout.Item1.TileColumns); if (null != displaySetLayout.Item2) { imageBox.DisplaySet = displaySetLayout.Item2.CreateFreshCopy(); } else { imageBox.DisplaySet = null; } imageBoxIndex++; } }
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 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(); }
private void UpdateEnabled() { IPhysicalWorkspace workspace = base.ImageViewer.PhysicalWorkspace; if (Checked) { base.Enabled = true; } else { base.Enabled = !workspace.Locked && workspace.ImageBoxes.Count > 1 && workspace.SelectedImageBox != null && workspace.SelectedImageBox.SelectedTile != null && workspace.SelectedImageBox.SelectedTile.PresentationImage != null; } }
int WorkspaceScreenCount() { IPhysicalWorkspace workspace = ImageViewer.PhysicalWorkspace; int count = 0; foreach (Screen screen in Screen.AllScreens) { if (Rectangle.Intersect(screen.WorkingArea, workspace.ScreenRectangle).IsEmpty) { continue; } count++; } return(count); }
/// <summary> /// Implementation of the <see cref="IDisposable"/> pattern /// </summary> /// <param name="disposing">True if this object is being disposed, false if it is being finalized</param> protected virtual void Dispose(bool disposing) { if (disposing) { ParentDesktopObject = null; if (_toolSet != null) { _toolSet.Dispose(); _toolSet = null; } StopLoadingPriors(); StopPrefetching(); if (_physicalWorkspace != null) { _physicalWorkspace.Dispose(); _physicalWorkspace = null; } if (_logicalWorkspace != null) { _logicalWorkspace.Dispose(); _logicalWorkspace = null; } if (_studyTree != null) { _studyTree.Dispose(); _studyTree = null; } if (_layoutManager != null) { _layoutManager.Dispose(); _layoutManager = null; } if (ExtensionData != null) { ExtensionData.Dispose(); ExtensionData = 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); }
public override bool Start(IMouseInformation mouseInformation) { if (mouseInformation.ClickCount < 2) { return(false); } IPhysicalWorkspace workspace = base.ImageViewer.PhysicalWorkspace; if (workspace == null) { return(false); } IImageBox imageBox = workspace.SelectedImageBox; if (imageBox == null) { return(false); } if (imageBox.SelectedTile == null || imageBox.SelectedTile.PresentationImage == null) { return(false); } // This tool could just be lumped into the explode image box tool, but I like the separation. if (ExplodeImageBoxTool.IsExploded(base.ImageViewer)) { return(false); } if (_unexplodeCommands.ContainsKey(imageBox)) { _unexplodeCommands[imageBox].Execute(); return(true); } else if (CanExplodeTiles(imageBox)) { ExplodeSelectedTile(imageBox); return(true); } return(false); }
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(); }
protected override void FillPhysicalWorkspace() { // Do our own filling. The base method clones the display set, which is: // 1. Time consuming, because of the header generation // 2. Useless, because it can never be shown, and the workspace is locked anyway so you don't need to "recover" the original // 3. Makes reslicing slow, since you generate two sets of presentation images // 4. All of the above IPhysicalWorkspace physicalWorkspace = ImageViewer.PhysicalWorkspace; IMprWorkspace mprWorkspace = ImageViewer.MprWorkspace; if (mprWorkspace.ImageSets.Count == 0) { return; } int imageSetIndex = 0; int displaySetIndex = 0; foreach (IImageBox imageBox in physicalWorkspace.ImageBoxes) { if (displaySetIndex == mprWorkspace.ImageSets[imageSetIndex].DisplaySets.Count) { imageSetIndex++; displaySetIndex = 0; if (imageSetIndex == mprWorkspace.ImageSets.Count) { break; } } imageBox.DisplaySet = mprWorkspace.ImageSets[imageSetIndex].DisplaySets[displaySetIndex]; imageBox.DisplaySetLocked = true; displaySetIndex++; } // Let's start out in the middle of each stack foreach (IImageBox imageBox in this.ImageViewer.PhysicalWorkspace.ImageBoxes) { imageBox.TopLeftPresentationImageIndex = imageBox.DisplaySet.PresentationImages.Count / 2; } }
/// <summary> /// Fills <see cref="IPhysicalWorkspace.ImageBoxes"/> with <see cref="IDisplaySet"/>s. /// </summary> /// <remarks> /// <para> /// By default, <see cref="IPhysicalWorkspace.ImageBoxes"/> is filled starting with the first /// <see cref="IImageSet"/>'s <see cref="IDisplaySet"/>, and continuing until there /// are no empty <see cref="IImageBox"/>es or all <see cref="IDisplaySet"/>s have been assigned to an <see cref="IImageBox"/>. /// </para> /// <para> /// Override this method to change how <see cref="IDisplaySet"/>s are assigned to <see cref="IPhysicalWorkspace.ImageBoxes"/>. /// </para> /// </remarks> protected virtual void FillPhysicalWorkspace() { IPhysicalWorkspace physicalWorkspace = ImageViewer.PhysicalWorkspace; ILogicalWorkspace logicalWorkspace = ImageViewer.LogicalWorkspace; if (logicalWorkspace.ImageSets.Count == 0) { return; } int imageSetIndex = 0; int displaySetIndex = 0; foreach (IImageBox imageBox in physicalWorkspace.ImageBoxes) { if (displaySetIndex == logicalWorkspace.ImageSets[imageSetIndex].DisplaySets.Count) { imageSetIndex++; displaySetIndex = 0; if (imageSetIndex == logicalWorkspace.ImageSets.Count) { break; } } //if (imageBox.Occpyed == true) //{ // displaySetIndex++; // continue; //} //if (imageBox.DisplaySet != null && (imageBox.DisplaySet.Description == logicalWorkspace.ImageSets[imageSetIndex].DisplaySets[displaySetIndex].Description)) //{ // displaySetIndex++; // continue; //} imageBox.DisplaySet = logicalWorkspace.ImageSets[imageSetIndex].DisplaySets[displaySetIndex].CreateFreshCopy(); //imageBox.Occpyed = true; displaySetIndex++; } }
private bool CanUnexplodeImageBox(IImageBox imageBox) { if (imageBox == null) { return(false); } IPhysicalWorkspace workspace = imageBox.ParentPhysicalWorkspace; if (workspace == null) { return(false); } if (imageBox.DisplaySet == null) { CancelExplodeMode(); return(false); } return(true); }
public static void SetImageBoxLayout(IImageViewer imageViewer, int rows, int columns) { Platform.CheckForNullReference(imageViewer, "imageViewer"); Platform.CheckArgumentRange(rows, 1, LayoutSettings.MaximumImageBoxRows, "rows"); Platform.CheckArgumentRange(columns, 1, LayoutSettings.MaximumImageBoxColumns, "columns"); IPhysicalWorkspace physicalWorkspace = imageViewer.PhysicalWorkspace; if (physicalWorkspace.Locked) { return; } var memorableCommand = new MemorableUndoableCommand(physicalWorkspace) { BeginState = physicalWorkspace.CreateMemento() }; var fillingStrategy = ImageBoxFillingStrategy.Create(); var context = new ImageBoxFillingStrategyContext(imageViewer, p => p.SetImageBoxGrid(rows, columns), imageBox => imageBox.SetTileGrid(1, 1)); fillingStrategy.SetContext(context); fillingStrategy.FillImageBoxes(); physicalWorkspace.Draw(); physicalWorkspace.SelectDefaultImageBox(); memorableCommand.EndState = physicalWorkspace.CreateMemento(); var historyCommand = new DrawableUndoableCommand(physicalWorkspace) { Name = SR.CommandLayoutImageBoxes }; historyCommand.Enqueue(memorableCommand); imageViewer.CommandHistory.AddCommand(historyCommand); }
public void AdvanceDisplaySets(int direction) { int displaySetIndex, imageSetIndex; GetIndex(out displaySetIndex, out imageSetIndex); if (-1 == displaySetIndex || -1 == imageSetIndex) { UpdateEnabled(); return; } IPhysicalWorkspace workspace = Context.Viewer.PhysicalWorkspace; MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(workspace); memorableCommand.BeginState = workspace.CreateMemento(); int newDisplaySetIndex; IImageSet imageSet; if ((direction > 0 && NextDisplaySetsAvailable) || (direction < 0 && PreviousDisplaySetsAvailable)) { newDisplaySetIndex = displaySetIndex + direction; imageSet = Context.Viewer.PhysicalWorkspace.ImageBoxes.First().DisplaySet.ParentImageSet; } else if (direction > 0 && NextStudyAvailable) { imageSet = Context.Viewer.LogicalWorkspace.ImageSets[imageSetIndex + 1]; LayoutPhysicalWorkspace(imageSet); newDisplaySetIndex = 0; } else if (direction < 0 && PreviousStudyAvailable) { imageSet = Context.Viewer.LogicalWorkspace.ImageSets[imageSetIndex - 1]; LayoutPhysicalWorkspace(imageSet); newDisplaySetIndex = (imageSet.DisplaySets.Count - 1) / Context.Viewer.PhysicalWorkspace.ImageBoxes.Count; } else { throw new ArgumentException("Unable to advance DisplaySets."); } int imageBoxIndex = 0; foreach (var imageBox in workspace.ImageBoxes) { int i = ((workspace.ImageBoxes.Count) * newDisplaySetIndex) + imageBoxIndex; if (i < imageSet.DisplaySets.Count) { imageBox.DisplaySet = imageSet.DisplaySets[i].CreateFreshCopy(); } else { imageBox.DisplaySet = null; } imageBoxIndex++; } workspace.Draw(); workspace.SelectDefaultImageBox(); memorableCommand.EndState = workspace.CreateMemento(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(workspace); historyCommand.Name = "AdvanceDisplaySet"; historyCommand.Enqueue(memorableCommand); Context.Viewer.CommandHistory.AddCommand(historyCommand); }