Beispiel #1
0
        public void Execute(params string[] parameters)
        {
            if (parameters.Length > 0)
            {
                Console.WriteLine("undo не нужны аргументы");
                return;
            }
            var shapes = CommandHistoryContainer.GetInstance().OnUndo();

            if (shapes == null)
            {
                Console.WriteLine("Нет действий, которые можно было бы откатить");
                return;
            }

            var currentShapes = picture.shapes;

            foreach (var shape in currentShapes.ToList())
            {
                picture.Remove(shape);
            }

            foreach (var shape in shapes)
            {
                picture.Add(shape);
            }

            SelectionContainer.GetInstance().OnUndo(picture.shapes);
        }
Beispiel #2
0
        public override void Execute(params string[] parameters)
        {
            try
            {
                var uniqueIndexes = new List <string>();
                var shapeLocators = new List <ShapeLocator>();

                if (parameters.Length < 1)
                {
                    throw new ArgumentException("Отсуствует аргумент");
                }

                foreach (var parameter in parameters)
                {
                    if (uniqueIndexes.IndexOf(parameter) == -1)
                    {
                        uniqueIndexes.Add(parameter);
                        shapeLocators.Add(ShapeLocator.Parse(parameter, picture));
                    }
                }

                foreach (var shapeLocator in shapeLocators)
                {
                    var shape  = shapeLocator.Shape;
                    var parent = shapeLocator.Parent;

                    if (parent != null)
                    {
                        parent.Shapes.Remove(shape);

                        if (parent.Shapes.Count < 2)
                        {
                            var grandParent = shapeLocator.GrandParent;
                            if (grandParent != null)
                            {
                                grandParent.Shapes.Add(parent.Shapes[0]);
                                grandParent.Shapes.Remove(parent);
                            }
                            else
                            {
                                picture.Add(parent.Shapes[0]);
                                picture.Remove(parent);
                            }
                        }
                    }
                    else
                    {
                        SelectionContainer.GetInstance().OnMainRemove(shape);
                        picture.Remove(shape);
                    }
                }

                UpdateHistory();
                SelectionContainer.GetInstance().OnMainRemove(picture);
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #3
0
        public void Ungroup(string[] indexes)
        {
            var shape = ShapeLocator.Parse(indexes[0], this);

            SelectionContainer.GetInstance().OnUngroup(shape);

            if (shape.Shape is CompoundShape)
            {
                var compoundShape = shape.Shape as CompoundShape;
                if (shape.Parent != null)
                {
                    shape.Parent.Shapes.Remove(shape.Shape);
                    foreach (var currentShape in compoundShape.Shapes)
                    {
                        shape.Parent.Shapes.Add(currentShape);
                    }
                }
                else
                {
                    Remove(shape.Shape);
                    foreach (var currentShape in compoundShape.Shapes)
                    {
                        Add(currentShape);
                    }
                }
            }
            else
            {
                throw new ArgumentException($"Фигура с указанным индексом '{indexes[0]}' не составная");
            }
        }
Beispiel #4
0
        protected IEnumerable <IShape> GetShapes(string[] parameters, int shapeIndex)
        {
            if (parameters.Length < shapeIndex)
            {
                var shapes = SelectionContainer.GetInstance().Shapes;
                if (shapes.Count == 0)
                {
                    throw new ArgumentException("Для команды необходимы аргументы либо выбор с помощью " +
                                                "команды 'select'");
                }

                return(shapes);
            }

            var shape = ShapeLocator.Parse(parameters[shapeIndex - 1], picture).Shape;

            return(new List <IShape> {
                shape
            });
        }
Beispiel #5
0
        public static ShapeLocator Parse(string identifier)
        {
            var shapeLocator     = new ShapeLocator();
            var identifierDecomp = identifier.Split(':');
            int index;

            if (identifierDecomp.Length > 0 && int.TryParse(identifierDecomp[0], out index))
            {
                try
                {
                    shapeLocator.Shape = SelectionContainer.GetInstance().Shapes[index];
                }
                catch (ArgumentOutOfRangeException)
                {
                    throw new ArgumentException("Фигуры с таким индетефикатором " + identifier + " не существует");
                }
            }
            else
            {
                throw new ArgumentException("Формат идеентификатора '" + identifier + "' не верен");
            }

            if (identifierDecomp.Length > 1)
            {
                int[] underPosition = new int[identifierDecomp.Length - 1];
                for (int i = 0; i < identifierDecomp.Length - 1; i++)
                {
                    if (!int.TryParse(identifierDecomp[i + 1], out underPosition[i]))
                    {
                        throw new ArgumentException("Формат идеентификатора '" + identifier + "' не верен");
                    }
                }
                Search(shapeLocator, underPosition);
            }

            return(shapeLocator);
        }