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);
		}
        /// <summary>
        /// Applies <paramref name="operation"/> to <paramref name="item"/> and returns
        /// an <see cref="UndoableCommand"/> that can undo and redo the operation.
        /// </summary>
        /// <returns>
        /// An <see cref="UndoableCommand"/> if application of <paramref name="operation"/>
        /// resulted in a change to the internal state of <paramref name="item"/>, otherwise null.
        /// </returns>
        /// <remarks>
        /// <para>
        /// The default implementation takes the <see cref="MemorableUndoableCommand"/> returned
        /// by the base method and wraps it in a <see cref="DrawableUndoableCommand"/>.
        /// </para>
        /// <para>
        /// Inheritors can override this method to do any additional processing and/or to
        /// modify the resulting command, if necessary.
        /// </para>
        /// </remarks>
        protected override UndoableCommand Apply(IUndoableOperation <T> operation, T item)
        {
            UndoableCommand command = base.Apply(operation, item);

            if (command != null)
            {
                item.Draw();

                DrawableUndoableCommand drawableCommand = new DrawableUndoableCommand(item);
                drawableCommand.Enqueue(command);
                command = drawableCommand;
            }

            return(command);
        }
Esempio n. 3
0
		public void Delete()
		{
			IGraphic graphic = base.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);
		}
Esempio n. 4
0
        /// <summary>
        /// Helper method for setting the display set of this image box.
        /// </summary>
        /// <param name="displaySet">The display set to show in this image box, or NULL to clear it.</param>
        /// <param name="createFreshCopy">Value indicating whether or not <see cref="IDisplaySet.CreateFreshCopy"/> should be called on the display set.</param>
        /// <param name="addToCommandHistory">Value indicating whether or not the viewer command history should be updated.</param>
        /// <param name="selectDefaultTile">Value indicating whether or not <see cref="IImageBox.SelectDefaultTile"/> should be called after updating the display set.</param>
        public void SetDisplaySet(IDisplaySet displaySet, bool createFreshCopy = false, bool addToCommandHistory = true, bool selectDefaultTile = true)
        {
            var memorableCommand = addToCommandHistory ? new MemorableUndoableCommand(this)
            {
                BeginState = CreateMemento()
            } : null;

            DisplaySet = displaySet != null && createFreshCopy?displaySet.CreateFreshCopy() : displaySet;

            Draw();
            if (selectDefaultTile)
            {
                SelectDefaultTile();
            }

            if (addToCommandHistory)
            {
                memorableCommand.EndState = CreateMemento();

                var historyCommand = new DrawableUndoableCommand(this);
                historyCommand.Enqueue(memorableCommand);
                ImageViewer.CommandHistory.AddCommand(historyCommand);
            }
        }
		internal static void DeleteAll(IPresentationImage image)
		{
			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));
		
			command.Execute();
			command.Name = SR.CommandDeleteAllAnnotations;
			image.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();
        }
        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();
        }