示例#1
0
        /// <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);
        }
        public void SubGrid(ImageDisplayFormat displayFormat)
        {
            if (RootImageBox.SelectedTile == null)
            {
                return;
            }

            var printViewTile = RootImageBox.SelectedTile as PrintViewTile;

            var memorableCommand = new MemorableUndoableCommand(RootImageBox)
            {
                BeginState = RootImageBox.CreateMemento()
            };
            List <PrintViewTile> selectTiles;

            if (RootImageBox.DisplaySet != null && RootImageBox.DisplaySet.PresentationImages.Count != 0)
            {
                selectTiles = new List <PrintViewTile>();
                foreach (var selectPresentationImage in RootImageBox.SelectPresentationImages)
                {
                    if (selectPresentationImage.Tile == null)
                    {
                        continue;
                    }
                    var tile = selectPresentationImage.Tile as PrintViewTile;
                    if (!selectTiles.Contains(tile) && !tile.isSubTile)
                    {
                        selectTiles.Add(tile);
                    }
                }

                if (!selectTiles.Contains(printViewTile) && !printViewTile.isSubTile)
                {
                    selectTiles.Add(printViewTile);
                }
            }
            else
            {
                selectTiles = new List <PrintViewTile>();
                foreach (var selectTile in RootImageBox.SelectTiles)
                {
                    if (!selectTiles.Contains(selectTile) && !selectTile.isSubTile)
                    {
                        selectTiles.Add(selectTile);
                    }
                }
            }

            if (selectTiles.Count == 0)
            {
                return;
            }



            foreach (var tile in selectTiles)
            {
                TileCollection collection = SetTileGridFactory(displayFormat);
                if (collection == null)
                {
                    continue;
                }
                SubGridFactory(displayFormat, ref collection, tile);
                int index = RootImageBox.Tiles.IndexOf(tile);
                RootImageBox.Tiles.Remove(tile);
                for (int i = collection.Count - 1; i >= 0; i--)
                {
                    var item = collection[i] as PrintViewTile;
                    item.isSubTile           = true;
                    item.ParentPrintViewTile = tile;
                    RootImageBox.Tiles.Insert(index, item);
                    tile.SubTiles.Add(item);
                }
            }
            EventsHelper.Fire(_layoutCompletedEvent, this, EventArgs.Empty);
            this.RootImageBox.TopLeftPresentationImageIndex = 0;
            this.RootImageBox.Draw();
            ClearSelectTiles();
            this.RootImageBox.SelectDefaultTile();
            memorableCommand.EndState = RootImageBox.CreateMemento();
            var historyCommand = new DrawableUndoableCommand(RootImageBox)
            {
                Name = "RootImageBoxSubGrid"
            };

            historyCommand.Enqueue(memorableCommand);
            CommandHistory.AddCommand(historyCommand);

            PropertyValueChanged();
        }
        public void MergerGrid()
        {
            if (RootImageBox.SelectedTile == null)
            {
                return;
            }

            var printViewTile = RootImageBox.SelectedTile as PrintViewTile;

            var memorableCommand = new MemorableUndoableCommand(RootImageBox)
            {
                BeginState = RootImageBox.CreateMemento()
            };
            List <PrintViewTile> selectTiles;

            if (RootImageBox.DisplaySet != null && RootImageBox.DisplaySet.PresentationImages.Count != 0)
            {
                selectTiles = new List <PrintViewTile>();
                foreach (var selectPresentationImage in RootImageBox.SelectPresentationImages)
                {
                    if (selectPresentationImage.Tile == null)
                    {
                        continue;
                    }
                    var tile = selectPresentationImage.Tile as PrintViewTile;
                    if (!selectTiles.Contains(tile))
                    {
                        selectTiles.Add(tile);
                    }
                }

                if (!selectTiles.Contains(printViewTile))
                {
                    selectTiles.Add(printViewTile);
                }
            }
            else
            {
                selectTiles = new List <PrintViewTile>();
                foreach (var selectTile in RootImageBox.SelectTiles)
                {
                    if (!selectTiles.Contains(selectTile))
                    {
                        selectTiles.Add(selectTile);
                    }
                }
            }

            if (selectTiles.Count <= 1)
            {
                return;
            }

            //合并单元格
            //并集合
            var mycell = RectangleF.Union(selectTiles[0].NormalizedRectangle, selectTiles[1].NormalizedRectangle);

            for (int i = 2; i < selectTiles.Count; i++)
            {
                mycell = RectangleF.Union(mycell, selectTiles[i].NormalizedRectangle);
            }

            //移出与合并之后相交的单元格
            var intersecTiles = new List <ITile>();

            foreach (var tile in RootImageBox.Tiles)
            {
                if (mycell.IntersectsWith(tile.NormalizedRectangle))
                {
                    intersecTiles.Add(tile);
                }
            }

            if (intersecTiles.Count == 0)
            {
                return;
            }
            //确定单元格的位置
            int index = RootImageBox.Tiles.IndexOf(intersecTiles[0]);

            if (index == -1)
            {
                return;
            }

            var mergerResult = new PrintViewTile();

            mergerResult.NormalizedRectangle = mycell;
            RootImageBox.Tiles.Insert(index, mergerResult);

            //移出相交的单元格
            foreach (var item in intersecTiles)
            {
                RootImageBox.Tiles.Remove(item);
            }

            EventsHelper.Fire(_layoutCompletedEvent, this, EventArgs.Empty);
            this.RootImageBox.TopLeftPresentationImageIndex = 0;
            this.RootImageBox.Draw();
            ClearSelectTiles();
            this.RootImageBox.SelectDefaultTile();
            memorableCommand.EndState = RootImageBox.CreateMemento();
            var historyCommand = new DrawableUndoableCommand(RootImageBox)
            {
                Name = "RootImageBoxMergerGrid"
            };

            historyCommand.Enqueue(memorableCommand);
            CommandHistory.AddCommand(historyCommand);

            PropertyValueChanged();
        }