コード例 #1
0
        /// <summary>
        ///   Initialization
        /// </summary>
        /// <param name="owner"> </param>
        /// <param name="docManager"> </param>
        public void Initialize(MainForm 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.Line]      = new ToolLine();
            _tools[(int)DrawToolType.Polygon]   = new ToolPolygon();
        }
コード例 #2
0
 /// <summary>
 /// This function is used to make Undo operation.
 /// It makes action opposite to the original command.
 /// </summary>
 /// <param name="list">Graphics list</param>
 public 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
 /// <summary>
 /// This function is used to make Undo operation.
 /// It makes action opposite to the original command.
 /// </summary>
 /// <param name="list">Graphics list</param>
 public void Undo(GraphicsList list)
 {
     // Add all objects from clone list to list -
     // opposite to DeleteAll
     foreach (DrawObject o in _cloneList)
     {
         list.Add(o);
     }
 }
コード例 #4
0
        public void Undo(GraphicsList list)
        {
            list.UnselectAll();

            // Add all objects from cloneList to list.
            foreach (DrawObject o in _cloneList)
            {
                list.Add(o);
            }
        }
コード例 #5
0
        public void Undo(GraphicsList list)
        {
            list.UnselectAll();

            // Add all objects from cloneList to list.
            foreach (DrawObject o in _cloneList)
            {
                list.Add(o);
            }
        }
コード例 #6
0
        private readonly List <DrawObject> _cloneList; // contains selected items which are deleted

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

            // Make clone of the list selection.

            foreach (DrawObject o in graphicsList.Selection)
            {
                _cloneList.Add(o.Clone());
            }
        }
コード例 #7
0
        private readonly List<DrawObject> _cloneList; // contains selected items which are deleted

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

            // Make clone of the list selection.

            foreach (DrawObject o in graphicsList.Selection)
            {
                _cloneList.Add(o.Clone());
            }
        }
コード例 #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 = list.FirstOrDefault(o => o.ID == graphicsList[i].ID);

                if (replacement != null)
                {
                    graphicsList.Replace(i, replacement);
                }
            }
        }
コード例 #9
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 = list.FirstOrDefault(o => o.ID == graphicsList[i].ID);

                if (replacement != null)
                {
                    graphicsList.Replace(i, replacement);
                }
            }
        }
コード例 #10
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());
            }
        }
コード例 #11
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());
            }
        }
コード例 #12
0
        public void Redo(GraphicsList list)
        {
            // Delete from list all objects kept in cloneList

            int n = list.Count;

            for (int i = n - 1; i >= 0; i--)
            {
                DrawObject objectToDelete = list[i];

                bool toDelete = _cloneList.Any(o => objectToDelete.ID == o.ID);

                if (toDelete)
                {
                    list.RemoveAt(i);
                }
            }
        }
コード例 #13
0
        public void Redo(GraphicsList list)
        {
            // Delete from list all objects kept in cloneList

            int n = list.Count;

            for (int i = n - 1; i >= 0; i--)
            {
                DrawObject objectToDelete = list[i];

                bool toDelete = _cloneList.Any(o => objectToDelete.ID == o.ID);

                if (toDelete)
                {
                    list.RemoveAt(i);
                }
            }
        }
コード例 #14
0
        // Call this function AFTER operation.

        #region ICommand Members

        /// <summary>
        /// This function is used to make Undo operation.
        /// It makes action opposite to the original command.
        /// </summary>
        /// <param name="list">Graphics list</param>
        public void Undo(GraphicsList list)
        {
            // Replace all objects in the list with objects from listBefore
            ReplaceObjects(list, _listBefore);
        }
コード例 #15
0
 // Create this command BEFORE operation.
 public CommandChangeState(GraphicsList graphicsList)
 {
     // Keep objects state before operation.
     FillList(graphicsList, ref _listBefore);
 }
コード例 #16
0
        /// <summary>
        ///   Right-click handler
        /// </summary>
        /// <param name="e"> </param>
        private void OnContextMenu(MouseEventArgs e)
        {
            // Change current selection if necessary

            var point = new Point(e.X, e.Y);

            int        n = GraphicsList.Count;
            DrawObject o = null;

            for (int i = 0; i < n; i++)
            {
                if (GraphicsList[i].HitTest(point) == 0)
                {
                    o = GraphicsList[i];
                    break;
                }
            }

            if (o != null)
            {
                if (!o.Selected)
                {
                    GraphicsList.UnselectAll();
                }

                // Select clicked object
                o.Selected = true;
            }
            else
            {
                GraphicsList.UnselectAll();
            }

            Refresh(); // in the case selection was changed

            // Show context menu.
            // Context menu items are filled from owner form Edit menu items.
            _contextMenu = new ContextMenuStrip();

//            int nItems = owner.ContextParent.DropDownItems.Count;

            // Read Edit items and move them to context menu.
            // Since every move reduces number of items, read them in reverse order.
            // To get items in direct order, insert each of them to beginning.
//            for (int i = nItems - 1; i >= 0; i--)
//            {
//                m_ContextMenu.Items.Insert(0, owner.ContextParent.DropDownItems[i]);
//            }

            // Show context menu for owner form, so that it handles items selection.
            // Convert point from this window coordinates to owner's coordinates.
            point.X += Left;
            point.Y += Top;

            //m_ContextMenu.Show(owner, point);

            //Owner.SetStateOfControls();  // enable/disable menu items

            // Context menu is shown, but owner's Edit menu is now empty.
            // Subscribe to context menu Closed event and restore items there.
            _contextMenu.Closed += delegate
            {
                if (_contextMenu != null)                            // precaution
                {
//                    nItems = m_ContextMenu.Items.Count;

//                    for (int k = nItems - 1; k >= 0; k--)
//                    {
//                        owner.ContextParent.DropDownItems.Insert(0, m_ContextMenu.Items[k]);
//                    }
                }
            };
        }
コード例 #17
0
ファイル: UndoManager.cs プロジェクト: gitter-badger/UROCare
        public UndoManager(GraphicsList graphicsList)
        {
            _graphicsList = graphicsList;

            ClearHistory();
        }
コード例 #18
0
        /// <summary>
        ///   Initialization
        /// </summary>
        /// <param name="owner"> </param>
        /// <param name="docManager"> </param>
        public void Initialize(MainForm 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.Line] = new ToolLine();
            _tools[(int) DrawToolType.Polygon] = new ToolPolygon();
        }
コード例 #19
0
 // Fill list from selection
 private void FillList(GraphicsList graphicsList, ref List<DrawObject> listToFill)
 {
     listToFill = graphicsList.Selection.Select(o => o.Clone()).ToList();
 }
コード例 #20
0
        // Call this function AFTER operation.

        #region ICommand Members

        /// <summary>
        /// This function is used to make Undo operation.
        /// It makes action opposite to the original command.
        /// </summary>
        /// <param name="list">Graphics list</param>
        public void Undo(GraphicsList list)
        {
            // Replace all objects in the list with objects from listBefore
            ReplaceObjects(list, _listBefore);
        }
コード例 #21
0
 public void NewState(GraphicsList graphicsList)
 {
     // Keep objects state after operation.
     FillList(graphicsList, ref _listAfter);
 }
コード例 #22
0
 /// <summary>
 /// This command is used to make Redo operation.
 /// It makes original command again.
 /// </summary>
 /// <param name="list">Graphics list</param>
 public void Redo(GraphicsList list)
 {
     // Clear list - make DeleteAll again
     list.Clear();
 }
コード例 #23
0
 /// <summary>
 /// This command is used to make Redo operation.
 /// It makes original command again.
 /// </summary>
 /// <param name="list">Graphics list</param>
 public void Redo(GraphicsList list)
 {
     // Clear list - make DeleteAll again
     list.Clear();
 }
コード例 #24
0
 // Create this command BEFORE operation.
 public CommandChangeState(GraphicsList graphicsList)
 {
     // Keep objects state before operation.
     FillList(graphicsList, ref _listBefore);
 }
コード例 #25
0
 // Fill list from selection
 private void FillList(GraphicsList graphicsList, ref List <DrawObject> listToFill)
 {
     listToFill = graphicsList.Selection.Select(o => o.Clone()).ToList();
 }
コード例 #26
0
 public void NewState(GraphicsList graphicsList)
 {
     // Keep objects state after operation.
     FillList(graphicsList, ref _listAfter);
 }
コード例 #27
0
 /// <summary>
 /// This command is used to make Redo operation.
 /// It makes original command again.
 /// </summary>
 /// <param name="list">Graphics list</param>
 public void Redo(GraphicsList list)
 {
     // Replace all objects in the list with objects from listAfter
     ReplaceObjects(list, _listAfter);
 }
コード例 #28
0
ファイル: UndoManager.cs プロジェクト: gitter-badger/UROCare
        public UndoManager(GraphicsList graphicsList)
        {
            _graphicsList = graphicsList;

            ClearHistory();
        }
コード例 #29
0
 /// <summary>
 /// This command is used to make Redo operation.
 /// It makes original command again.
 /// </summary>
 /// <param name="list">Graphics list</param>
 public void Redo(GraphicsList list)
 {
     // Replace all objects in the list with objects from listAfter
     ReplaceObjects(list, _listAfter);
 }