Esempio n. 1
0
        /// <summary>
        /// 撤销添加直线
        /// </summary>
        /// <param name="command"></param>
        public void UnAddLine(AddLineCommand command)
        {
            foreach (Rect rect in command.RemovedRects)
            {
                rect.IsDeleted = false;
            }

            foreach (Rect rect in command.AddedRects)
            {
                rect.IsDeleted = true;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 添加直线
        /// </summary>
        /// <param name="command"></param>
        public void AddLine(AddLineCommand command)
        {
            if (!command.IsRedo)///是第一次插入直线,而非重做撤销的插入直线命令
            {
                ///找到所有被分割之矩形
                PartitionLine  line        = new PartitionLine(command.Start, command.End, command.Position, command.IsRow);
                FindRectByLine findRect    = new FindRectByLine(line);
                List <Rect>    resultRects = SnipRectList.FindAll(findRect.PartitionLinePredicate);

                for (int i = 0; i < resultRects.Count; i++)
                {
                    command.RemovedRects.Add(resultRects[i]);
                    if (line.IsRow)
                    {
                        Rect firstRect = TDPanel.CreateRect(
                            resultRects[i].X,
                            resultRects[i].Y,
                            resultRects[i].Width,
                            line.Position - resultRects[i].Y
                            );
                        Rect secondRect = TDPanel.CreateRect(
                            resultRects[i].X,
                            line.Position,
                            resultRects[i].Width,
                            resultRects[i].Y + resultRects[i].Height - line.Position
                            );

                        // SnipRectList.Remove(resultRects[i]);
                        resultRects[i].IsDeleted = true;

                        SnipRectList.Add(firstRect);
                        SnipRectList.Add(secondRect);
                        command.AddedRects.Add(firstRect);
                        command.AddedRects.Add(secondRect);
                    }
                    else
                    {
                        Rect firstRect = TDPanel.CreateRect(
                            resultRects[i].X,
                            resultRects[i].Y,
                            line.Position - resultRects[i].X,
                            resultRects[i].Height
                            );
                        Rect secondRect = TDPanel.CreateRect(
                            line.Position,
                            resultRects[i].Y,
                            resultRects[i].Width + resultRects[i].X - line.Position,
                            resultRects[i].Height
                            );
                        //SnipRectList.Remove(resultRects[i]);
                        resultRects[i].IsDeleted = true;
                        SnipRectList.Add(firstRect);
                        SnipRectList.Add(secondRect);
                        command.AddedRects.Add(firstRect);
                        command.AddedRects.Add(secondRect);
                    }
                }
                command.IsRedo = true;
            }
            else///重做撤销的插入直线命令
            {
                foreach (Rect rect in command.RemovedRects)
                {
                    rect.IsDeleted = true;
                }

                foreach (Rect rect in command.AddedRects)
                {
                    rect.IsDeleted = false;
                }
            }
        }