예제 #1
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            CompoundHistoryMemento chm = new CompoundHistoryMemento(this.historyName, this.undoImage);

            if (!historyWorkspace.Selection.IsEmpty)
            {
                DeselectFunction df = new DeselectFunction();
                EnterCriticalRegion();
                HistoryMemento hm = df.Execute(historyWorkspace);
                chm.PushNewAction(hm);
            }

            FlipLayerHistoryMemento flha = new FlipLayerHistoryMemento(
                null,
                null,
                historyWorkspace,
                this.layerIndex,
                this.flipType);

            EnterCriticalRegion();
            HistoryMemento flha2 = flha.PerformUndo();

            chm.PushNewAction(flha);

            return(chm);
        }
예제 #2
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            object savedSelection         = null;
            List <HistoryMemento> actions = new List <HistoryMemento>();

            if (!historyWorkspace.Selection.IsEmpty)
            {
                savedSelection = historyWorkspace.Selection.Save();
                DeselectFunction da = new DeselectFunction();
                HistoryMemento   hm = da.Execute(historyWorkspace);
                actions.Add(hm);
            }

            ReplaceDocumentHistoryMemento rdha = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);

            actions.Add(rdha);

            CompoundHistoryMemento chm = new CompoundHistoryMemento(
                StaticName,
                PdnResources.GetImageResource("Icons.MenuImageFlattenIcon.png"),
                actions);

            // TODO: we can save memory here by serializing, then flattening on to an existing layer
            Document flat = historyWorkspace.Document.Flatten();

            EnterCriticalRegion();
            historyWorkspace.Document = flat;

            if (savedSelection != null)
            {
                SelectionHistoryMemento shm = new SelectionHistoryMemento(null, null, historyWorkspace);
                historyWorkspace.Selection.Restore(savedSelection);
                chm.PushNewAction(shm);
            }

            return(chm);
        }
예제 #3
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            List <HistoryMemento> actions = new List <HistoryMemento>();

            if (!historyWorkspace.Selection.IsEmpty)
            {
                DeselectFunction da = new DeselectFunction();
                EnterCriticalRegion();
                HistoryMemento hm = da.Execute(historyWorkspace);
                actions.Add(hm);
            }

            int count = historyWorkspace.Document.Layers.Count;

            for (int i = 0; i < count; ++i)
            {
                HistoryMemento memento = new FlipLayerHistoryMemento(this.historyName, undoImage, historyWorkspace, i, flipType);
                EnterCriticalRegion();
                HistoryMemento mementoToAdd = memento.PerformUndo();
                actions.Add(mementoToAdd);
            }

            return(new CompoundHistoryMemento(this.historyName, undoImage, actions));
        }
예제 #4
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            int newWidth;
            int newHeight;

            // Get new width and Height
            switch (rotation)
            {
            case RotateType.Clockwise90:
            case RotateType.CounterClockwise90:
                newWidth  = historyWorkspace.Document.Height;
                newHeight = historyWorkspace.Document.Width;
                break;

            case RotateType.Rotate180:
                newWidth  = historyWorkspace.Document.Width;
                newHeight = historyWorkspace.Document.Height;
                break;

            default:
                throw new InvalidEnumArgumentException("invalid RotateType");
            }

            // Figure out which icon and text to use
            string iconResName;
            string suffix;

            switch (rotation)
            {
            case RotateType.Rotate180:
                iconResName = "Icons.MenuImageRotate180Icon.png";
                suffix      = PdnResources.GetString("RotateAction.180");
                break;

            case RotateType.Clockwise90:
                iconResName = "Icons.MenuImageRotate90CWIcon.png";
                suffix      = PdnResources.GetString("RotateAction.90CW");
                break;

            case RotateType.CounterClockwise90:
                iconResName = "Icons.MenuImageRotate90CCWIcon.png";
                suffix      = PdnResources.GetString("RotateAction.90CCW");
                break;

            default:
                throw new InvalidEnumArgumentException("invalid RotateType");
            }

            // Initialize the new Doc
            string        haNameFormat = PdnResources.GetString("RotateAction.HistoryMementoName.Format");
            string        haName       = string.Format(haNameFormat, StaticName, suffix);
            ImageResource haImage      = PdnResources.GetImageResource(iconResName);

            List <HistoryMemento> actions = new List <HistoryMemento>();

            // do the memory allocation now: if this fails, we can still bail out cleanly
            Document newDoc = new Document(newWidth, newHeight);

            if (!historyWorkspace.Selection.IsEmpty)
            {
                DeselectFunction da = new DeselectFunction();
                EnterCriticalRegion();
                HistoryMemento hm = da.Execute(historyWorkspace);
                actions.Add(hm);
            }

            ReplaceDocumentHistoryMemento rdha = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);

            actions.Add(rdha);

            newDoc.ReplaceMetaDataFrom(historyWorkspace.Document);

            // TODO: serialize oldDoc to disk, and let the GC purge it if needed
            OnProgress(0.0);

            for (int i = 0; i < historyWorkspace.Document.Layers.Count; ++i)
            {
                Layer layer = historyWorkspace.Document.Layers.GetAt(i);

                double progressStart = 100.0 * ((double)i / (double)historyWorkspace.Document.Layers.Count);
                double progressEnd   = 100.0 * ((double)(i + 1) / (double)historyWorkspace.Document.Layers.Count);

                if (layer is BitmapLayer)
                {
                    Layer nl = RotateLayer((BitmapLayer)layer, rotation, newWidth, newHeight, progressStart, progressEnd);
                    newDoc.Layers.Add(nl);
                }
                else
                {
                    throw new InvalidOperationException("Cannot Rotate non-BitmapLayers");
                }

                if (this.PleaseCancel)
                {
                    break;
                }

                OnProgress(progressEnd);
            }

            CompoundHistoryMemento chm = new CompoundHistoryMemento(
                haName,
                haImage,
                actions);

            if (this.PleaseCancel)
            {
                chm = null;
            }
            else
            {
                EnterCriticalRegion();
                historyWorkspace.Document = newDoc;
            }

            return(chm);
        }