Пример #1
0
        /// <summary>
        /// Initialization
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="docManager"></param>
        public void Initialize(NetBuilder owner, DocManager docManager)
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint |
                     ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);

            // Keep reference to owner form
            this.Owner      = owner;
            this.DocManager = docManager;

            // set default tool
            activeTool = DrawToolType.Pointer;

            // create list of graphic objects
            graphicsList = new GraphicsList();

            // Create undo manager
            undoManager = new UndoManager(graphicsList);

            // create array of drawing tools
            tools = new Tool[(int)DrawToolType.NumberOfDrawTools];
            tools[(int)DrawToolType.Pointer]   = new ToolPointer();
            tools[(int)DrawToolType.Rectangle] = new ToolRectangle();
            tools[(int)DrawToolType.Ellipse]   = new ToolEllipse();
            tools[(int)DrawToolType.Triangle]  = new ToolTriangle();
            tools[(int)DrawToolType.Line]      = new ToolLine();
            tools[(int)DrawToolType.Polygon]   = new ToolPolygon();
        }
Пример #2
0
 public override void Undo(GraphicsList list)
 {
     // Add all objects from clone list to list -
     // opposite to DeleteAll
     foreach (DrawObject o in cloneList)
     {
         list.Add(o);
     }
 }
Пример #3
0
        // Fill list from selection
        private void FillList(GraphicsList graphicsList, ref List <DrawObject> listToFill)
        {
            listToFill = new List <DrawObject>();

            foreach (DrawObject o in graphicsList.Selection)
            {
                listToFill.Add(o.Clone());
            }
        }
Пример #4
0
        public override void Redo(GraphicsList list)
        {
            // Delete from list all objects kept in cloneList

            int n = indexList.Count;

            for (int i = n - 1; i >= 0; i--)
            {
                list.RemoveAt(indexList[i]);
            }
        }
Пример #5
0
        public override void Undo(GraphicsList list)
        {
            list.UnselectAll();

            // Add all objects from cloneList to list.

            int n = cloneList.Count;

            for (int i = n - 1; i >= 0; i--)
            {
                list.Insert(indexList[i], cloneList[i]);
            }
        }
Пример #6
0
        // Create this command BEFORE applying Delete All function.
        public CommandDeleteAll(GraphicsList graphicsList)
        {
            cloneList = new List <DrawObject>();

            // Make clone of the whole list.
            // Add objects in reverse order because GraphicsList.Add
            // insert every object to the beginning.
            int n = graphicsList.Count;

            for (int i = n - 1; i >= 0; i--)
            {
                cloneList.Add(graphicsList[i].Clone());
            }
        }
Пример #7
0
        List <int> indexList;           // contains index of selected items which are deleted

        // Create this command BEFORE applying Delete All function.
        public CommandDelete(GraphicsList graphicsList)
        {
            cloneList = new List <DrawObject>();
            indexList = new List <int>();

            // Make clone of the list selection.

            int n = graphicsList.Count;

            for (int i = n - 1; i >= 0; i--)
            {
                if (graphicsList[i].Selected)
                {
                    cloneList.Add(graphicsList[i].Clone());
                    indexList.Add(i);
                }
            }
        }
Пример #8
0
        // Replace objects in graphicsList with objects from list
        private void ReplaceObjects(GraphicsList graphicsList, List <DrawObject> list)
        {
            for (int i = 0; i < graphicsList.Count; i++)
            {
                DrawObject replacement = null;

                foreach (DrawObject o in list)
                {
                    if (o.ID == graphicsList[i].ID)
                    {
                        replacement = o;
                        break;
                    }
                }

                if (replacement != null)
                {
                    graphicsList.Replace(i, replacement);
                }
            }
        }
Пример #9
0
 // This command is used to make Redo operation.
 // It makes original command again.
 public abstract void Redo(GraphicsList list);
Пример #10
0
 public override void Redo(GraphicsList list)
 {
     // Clear list - make DeleteAll again
     list.Clear();
 }
Пример #11
0
 // Call this function AFTER operation.
 public void NewState(GraphicsList graphicsList)
 {
     // Keep objects state after operation.
     FillList(graphicsList, ref listAfter);
 }
Пример #12
0
 public override void Redo(GraphicsList list)
 {
     list.UnselectAll();
     list.Add(drawObject);
 }
Пример #13
0
 public override void Undo(GraphicsList list)
 {
     list.DeleteLastAddedObject();
 }
Пример #14
0
 public override void Redo(GraphicsList list)
 {
     // Replace all objects in the list with objects from listAfter
     ReplaceObjects(list, listAfter);
 }
Пример #15
0
 public override void Undo(GraphicsList list)
 {
     // Replace all objects in the list with objects from listBefore
     ReplaceObjects(list, listBefore);
 }
Пример #16
0
        public UndoManager(GraphicsList graphicsList)
        {
            this.graphicsList = graphicsList;

            ClearHistory();
        }
Пример #17
0
 // Create this command BEFORE operation.
 public CommandChangeState(GraphicsList graphicsList)
 {
     // Keep objects state before operation.
     FillList(graphicsList, ref listBefore);
 }