示例#1
0
        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();
        }
示例#2
0
        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();
        }
示例#3
0
        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 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);
        }
示例#5
0
        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 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);
        }
示例#7
0
        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);
        }