Exemplo n.º 1
0
        private void DoUndoEdit(UndoOperation operation)
        {
            if (operation.lines != null)
            {
                foreach (Line lineOld in operation.lines)
                {
                    lineOld.startNode = this.diagram.GetNodeByID(lineOld.start);
                    lineOld.endNode   = this.diagram.GetNodeByID(lineOld.end);
                    Line line = this.diagram.layers.GetLine(lineOld.startNode, lineOld.endNode);

                    if (line != null)
                    {
                        line.Set(lineOld);
                    }
                }
            }

            if (operation.nodes != null)
            {
                foreach (Node nodeOld in operation.nodes)
                {
                    Node node = this.diagram.layers.GetNode(nodeOld.id);

                    if (node != null)
                    {
                        node.Set(nodeOld);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Check if operation is same as previous operation
        /// If previous operation is move node (by arrow forexample) is better group operation like one big move instead of many small moves.
        /// </summary>
        public bool IsSame(string type, Nodes nodes, Lines lines)
        {
            if (operations.Count() > 0)
            {
                UndoOperation operation = operations.First();

                if (operation.type == type)
                {
                    if (operation.nodes.Count() == 0 && nodes == null)
                    {
                    }
                    else if ((operation.nodes == null && nodes != null) || (operation.nodes != null && nodes == null))
                    {
                        return(false);
                    }
                    else if (operation.nodes.Count() == nodes.Count())
                    {
                        for (int i = 0; i < nodes.Count(); i++)
                        {
                            if (operation.nodes[i].id != nodes[i].id)
                            {
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }

                    if (operation.lines.Count() == 0 && lines == null)
                    {
                    }
                    else if ((operation.lines == null && lines != null) || (operation.lines != null && lines == null))
                    {
                        return(false);
                    }
                    else if (operation.lines.Count() == lines.Count())
                    {
                        for (int i = 0; i < lines.Count(); i++)
                        {
                            if (operation.lines[i].start != lines[i].start || operation.lines[i].end != lines[i].end)
                            {
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }

                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        private void DoUndoCreate(UndoOperation operation)
        {
            if (operation.lines != null)
            {
                foreach (Line line in operation.lines)
                {
                    this.diagram.layers.RemoveLine(line.start, line.end);
                }
            }

            if (operation.nodes != null)
            {
                foreach (Node node in operation.nodes)
                {
                    this.diagram.layers.RemoveNode(node.id);
                }
            }
        }
Exemplo n.º 4
0
        /*************************************************************************************************************************/
        // EVERSE OPERATION BY TYPE

        private void DoUndoDelete(UndoOperation operation)
        {
            if (operation.nodes != null)
            {
                foreach (Node node in operation.nodes)
                {
                    this.diagram.layers.AddNode(node);
                }
            }

            if (operation.lines != null)
            {
                foreach (Line line in operation.lines)
                {
                    line.startNode = this.diagram.GetNodeByID(line.start);
                    line.endNode   = this.diagram.GetNodeByID(line.end);
                    this.diagram.layers.AddLine(line);
                }
            }
        }
Exemplo n.º 5
0
        public bool DoRedo(DiagramView view = null)
        {
            if (reverseOperations.Count() == 0)
            {
                return(false);
            }

            long group  = 0;
            bool result = false;

            do
            {
                UndoOperation operation = reverseOperations.First();

                // first restore position where change occurred
                if (view != null && !view.IsOnPosition(operation.position, operation.scale, operation.layer))
                {
                    view.GoToPosition(operation.position, operation.scale, operation.layer);
                    view.Invalidate();
                    return(false);
                }

                // process all operations in same group
                if (group != 0 && operation.group != group)
                {
                    group = 0;
                    break;
                }

                group = operation.group;

                if (operation.type == "delete")
                {
                    this.DoUndoCreate(operation);
                    operations.Push(operation);
                }

                if (operation.type == "create")
                {
                    this.DoUndoDelete(operation);
                    operations.Push(operation);
                }

                if (operation.type == "edit" ||
                    operation.type == "move" ||
                    operation.type == "changeLineColor" ||
                    operation.type == "changeLineWidth" ||
                    operation.type == "changeNodeColor"
                    )
                {
                    Nodes nodes = new Nodes();
                    foreach (Node node in operation.nodes)
                    {
                        nodes.Add(this.diagram.GetNodeByID(node.id));
                    }

                    Lines lines = new Lines();
                    foreach (Line line in operation.lines)
                    {
                        lines.Add(this.diagram.GetLine(line.start, line.end));
                    }


                    UndoOperation roperation = new UndoOperation(
                        operation.type,
                        nodes,
                        lines,
                        operation.group,
                        operation.position,
                        operation.scale,
                        operation.layer
                        );

                    operations.Push(roperation);
                    this.DoUndoEdit(operation);
                }

                reverseOperations.Pop();
                result = true;
            } while (group != 0 && reverseOperations.Count() > 0);

            if (result)
            {
                this.saved++;
                if (!this.saveLost && this.saved == 0)
                {
                    this.diagram.Restoresave();
                }
                else
                {
                    this.diagram.Unsave();
                }
            }

            return(result);
        }
Exemplo n.º 6
0
        private void doUndoEdit(UndoOperation operation)
        {
            if (operation.lines != null)
            {
                foreach (Line lineOld in operation.lines)
                {
                    lineOld.startNode = this.diagram.GetNodeByID(lineOld.start);
                    lineOld.endNode = this.diagram.GetNodeByID(lineOld.end);
                    Line line = this.diagram.layers.getLine(lineOld.startNode, lineOld.endNode);

                    if (line != null)
                    {
                        line.set(lineOld);
                    }
                }
            }

            if (operation.nodes != null)
            {
                foreach (Node nodeOld in operation.nodes)
                {
                    Node node = this.diagram.layers.getNode(nodeOld.id);

                    if (node != null)
                    {
                        node.set(nodeOld);
                    }
                }
            }
        }
Exemplo n.º 7
0
        /*************************************************************************************************************************/
        // EVERSE OPERATION BY TYPE
        private void doUndoDelete(UndoOperation operation)
        {
            if (operation.nodes != null)
            {
                foreach (Node node in operation.nodes)
                {
                    this.diagram.layers.addNode(node);
                }
            }

            if (operation.lines != null)
            {
                foreach (Line line in operation.lines)
                {
                    line.startNode = this.diagram.GetNodeByID(line.start);
                    line.endNode = this.diagram.GetNodeByID(line.end);
                    this.diagram.layers.addLine(line);
                }
            }
        }
Exemplo n.º 8
0
        private void doUndoCreate(UndoOperation operation)
        {
            if (operation.lines != null)
            {
                foreach (Line line in operation.lines)
                {
                    this.diagram.layers.removeLine(line.start, line.end);
                }
            }

            if (operation.nodes != null)
            {
                foreach (Node node in operation.nodes)
                {
                    this.diagram.layers.removeNode(node.id);
                }
            }
        }
Exemplo n.º 9
0
        public bool doUndo(DiagramView view = null)
        {
            if (operations.Count() == 0)
            {
                return false;
            }

            int group = 0;

            bool result = false;

            do
            {
                UndoOperation operation = operations.First();

                // first restore position where change occurred
                if (view != null && !view.isOnPosition(operation.position, operation.layer))
                {
                    view.goToShift(operation.position);
                    view.goToLayer(operation.layer);
                    view.Invalidate();
                    return false;
                }

                // process all operations in same group
                if (group != 0 && operation.group != group)
                {
                    group = 0;
                    break;
                }

                group = operation.group;

                if (operation.type == "delete")
                {
                    this.doUndoDelete(operation);
                    reverseOperations.Push(operation);
                }

                if (operation.type == "create")
                {
                    this.doUndoCreate(operation);
                    reverseOperations.Push(operation);
                }

                if (operation.type == "edit" ||
                    operation.type == "move" ||
                    operation.type == "changeLineColor" ||
                    operation.type == "changeLineWidth" ||
                    operation.type == "changeNodeColor"
                )
                {
                    Nodes nodes = new Nodes();
                    foreach (Node node in operation.nodes)
                    {
                        nodes.Add(this.diagram.GetNodeByID(node.id));
                    }

                    Lines lines = new Lines();
                    foreach (Line line in operation.lines)
                    {
                        lines.Add(this.diagram.getLine(line.start, line.end));
                    }

                    UndoOperation roperation = new UndoOperation(
                        operation.type,
                        nodes,
                        lines,
                        operation.group,
                        operation.position,
                        operation.layer
                    );
                    reverseOperations.Push(roperation);
                    this.doUndoEdit(operation);
                }

                operations.Pop();
                result = true;
            } while (group != 0 && operations.Count() > 0);

            if (result)
            {
                this.saved--;
                if (!this.saveLost && this.saved == 0)
                {
                    this.diagram.restoresave();
                }
                else
                {
                    this.diagram.unsave();
                }
            }

            return result;
        }