Ejemplo n.º 1
0
        public override void Redo(GraphicsList list)
        {
            // Delete from list all objects kept in cloneList

            int n = list.Count;

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

                foreach (DrawObject o in cloneList)
                {
                    if (objectToDelete.ID == o.ID)
                    {
                        toDelete = true;
                        break;
                    }
                }

                if (toDelete)
                {
                    list.RemoveAt(i);
                }
            }
        }
Ejemplo n.º 2
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();
            //AdjustRendering();

            this.initialized = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initialization
        /// </summary>
        /// <param name="owner"></param>
        public void Initialize(Control owner)
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint |
                     ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);

            // Keep reference to owner form
            Owner = owner;

            // set default tool
            _activeTool = DrawToolType.Pointer;

            // create list of graphic objects
            _graphicsList = new 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();
            _tools[(int)DrawToolType.Text]      = new ToolText();
            _tools[(int)DrawToolType.Bitmap]    = new ToolImage();
            _tools[(int)DrawToolType.Pan]       = new ToolPan();
            _tools[(int)DrawToolType.Path]      = new ToolPath();

            Graphics g = Owner.CreateGraphics();

            DrawObject.Dpi = new PointF(g.DpiX, g.DpiY);
        }
Ejemplo n.º 4
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());
            }
        }
Ejemplo n.º 5
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());
            }
        }
Ejemplo n.º 6
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);
     }
 }
Ejemplo n.º 7
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);
     }
 }
Ejemplo n.º 8
0
        public override void Undo(GraphicsList list)
        {
            list.UnselectAll();

            // Add all objects from cloneList to list.
            foreach (DrawObject o in cloneList)
            {
                list.Add(o);
            }
        }
Ejemplo n.º 9
0
        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());
            }
        }
Ejemplo n.º 10
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]);
            }
        }
Ejemplo n.º 11
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]);
            }
        }
Ejemplo n.º 12
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]);
            }
        }
Ejemplo n.º 13
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]);
            }
        }
Ejemplo n.º 14
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());
            }
        }
Ejemplo n.º 15
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());
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Initialization
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="docManager"></param>
        public void Initialize()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint |
                     ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);

            // set default tool
            activeTool = DrawToolType.Pointer;

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

            // create array of drawing tools
            tools = new Tool[(int)DrawToolType.NumberOfDrawTools];
            tools[(int)DrawToolType.Pointer] = new ToolPointer();
        }
Ejemplo n.º 17
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;
                _bringToFrontToolStripMenuItem.Enabled = true;
                _sendToBackToolStripMenuItem.Enabled   = true;
                _cutToolStripMenuItem.Enabled          = true;
                _copyToolStripMenuItem.Enabled         = true;
                _deleteToolStripMenuItem.Enabled       = true;
            }
            else
            {
                _bringToFrontToolStripMenuItem.Enabled = false;
                _sendToBackToolStripMenuItem.Enabled   = false;
                _cutToolStripMenuItem.Enabled          = false;
                _copyToolStripMenuItem.Enabled         = false;
                _deleteToolStripMenuItem.Enabled       = false;
                GraphicsList.UnselectAll();
            }

            _pasteToolStripMenuItem.Enabled = GraphicsList.AreItemsInMemory();
            _contextMenuStrip.Show(MousePosition);
            Refresh();
        }
Ejemplo n.º 18
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);
                }
            }
        }
Ejemplo n.º 19
0
        List<int> indexList; // contains index of selected items which are deleted

        #endregion Fields

        #region Constructors

        // 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);
                }
            }
        }
Ejemplo n.º 20
0
        public void LoadFromStream(SerializationInfo info, int orderNumber)
        {
            _graphicsList = new GraphicsList();

            _name = info.GetString(
                String.Format(CultureInfo.InvariantCulture,
                              "{0}{1}",
                              entryLayerName, orderNumber));

            _visible = info.GetBoolean(
                String.Format(CultureInfo.InvariantCulture,
                              "{0}{1}",
                              entryLayerVisible, orderNumber));

            _active = info.GetBoolean(
                String.Format(CultureInfo.InvariantCulture,
                              "{0}{1}",
                              entryLayerActive, orderNumber));

            int n = info.GetInt32(
                String.Format(CultureInfo.InvariantCulture,
                              "{0}{1}",
                              entryGraphicsCount, orderNumber));

            for (int i = 0; i < n; i++)
            {
                string typeName;
                typeName = info.GetString(
                    String.Format(CultureInfo.InvariantCulture,
                                  "{0}{1}-{2}",
                                  entryObjectType, orderNumber, i));

                object drawObject;
                drawObject = Assembly.GetExecutingAssembly().CreateInstance(typeName);

                ((DrawObject)drawObject).LoadFromStream(info, orderNumber, i);

                // Thanks to Member 3272353 for this fix to object ordering problem.
                // _graphicsList.Add((DrawObject)drawObject);
                _graphicsList.Append((DrawObject)drawObject);
            }
        }
Ejemplo n.º 21
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);
                }
            }
        }
Ejemplo n.º 22
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);
                }
            }
        }
Ejemplo n.º 23
0
        private static Point TestForConnection(DrawArea drawArea, Point p, out int objectID)
        {
            // Determine if within 5 pixels of a connection point
            // Step 1: see if a 5 x 5 rectangle centered on the mouse cursor intersects with an object
            // Step 2: If it does, then see if there is a connection point within the rectangle
            // Step 3: If there is, move the point to the connection point, record the object's id in the connector
            //
            objectID = -1;
            Rectangle    testRectangle  = new Rectangle(p.X - 2, p.Y - 2, 5, 5);
            int          al             = drawArea.TheLayers.ActiveLayerIndex;
            bool         connectionHere = false;
            Point        h  = new Point(-1, -1);
            GraphicsList gl = drawArea.TheLayers[al].Graphics;

            for (int i = 1; i < gl.Count; i++)
            {
                if (gl[i].IntersectsWith(testRectangle))
                {
                    DrawObject obj = (DrawObject)gl[i];
                    for (int j = 1; j < obj.HandleCount + 1; j++)
                    {
                        h = obj.GetHandle(j);
                        if (testRectangle.Contains(h))
                        {
                            connectionHere = true;
                            p        = h;
                            objectID = obj.ID;
                            //			obj.DrawConnection(drawArea., j);
                            break;
                        }
                    }
                }
                if (connectionHere)
                {
                    break;
                }
            }
            return(p);
        }
Ejemplo n.º 24
0
        public void Initialize(Control owner)
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint |
                     ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);

            Owner       = owner;
            _activeTool = DrawToolType.Pointer;

            _graphicsList = new GraphicsList();

            _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();
            _tools[(int)DrawToolType.Text]      = new ToolText();
            _tools[(int)DrawToolType.Path]      = new ToolPath();

            Graphics g = Owner.CreateGraphics();

            DrawObject.Dpi = new PointF(g.DpiX, g.DpiY);
        }
Ejemplo n.º 25
0
 public override void Redo(GraphicsList list)
 {
     // Clear list - make DeleteAll again
     list.Clear();
 }
Ejemplo n.º 26
0
 // Create this command BEFORE operation.
 public CommandChangeState(GraphicsList graphicsList)
 {
     // Keep objects state before operation.
     FillList(graphicsList, ref listBefore);
 }
Ejemplo n.º 27
0
 public void IsDirty(GraphicsList gList)
 {
     AdjustRendering();
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Right-click handler
        /// </summary>
        /// <param name="e"></param>
        private void OnContextMenu(MouseEventArgs e)
        {
            // Change current selection if necessary

            Point point = new Point(Math.Abs(this.AutoScrollPosition.X) + e.X, Math.Abs(this.AutoScrollPosition.Y) + 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.
            m_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 pointscroll from this window coordinates to owner's coordinates.
            point.X += this.Left;
            point.Y += this.Top;

            Point org = new Point(e.X, e.Y);

            m_ContextMenu.Show(owner, org);

            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.
            m_ContextMenu.Closed += delegate(object sender, ToolStripDropDownClosedEventArgs args)
            {
                if (m_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]);
                    }
                }
            };
        }
Ejemplo n.º 29
0
 public override void Redo(GraphicsList list)
 {
     list.UnselectAll();
     list.Add(drawObject);
 }
Ejemplo n.º 30
0
 public override void Undo(GraphicsList list)
 {
     // Replace all objects in the list with objects from listBefore
     ReplaceObjects(list, listBefore);
 }
Ejemplo n.º 31
0
        public UndoManager(GraphicsList graphicsList)
        {
            this.graphicsList = graphicsList;

            ClearHistory();
        }
Ejemplo n.º 32
0
 public override void Undo(GraphicsList list)
 {
     // Replace all objects in the list with objects from listBefore
     ReplaceObjects(list, listBefore);
 }
Ejemplo n.º 33
0
 public override void Undo(GraphicsList list)
 {
     list.DeleteLastAddedObject();
 }
Ejemplo n.º 34
0
 // This command is used to make Redo operation.
 // It makes original command again.
 public abstract void Redo(GraphicsList list);
Ejemplo n.º 35
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.Triangle] = new ToolTriangle();
            tools[(int)DrawToolType.Line] = new ToolLine();
            tools[(int)DrawToolType.Polygon] = new ToolPolygon();
        }
Ejemplo n.º 36
0
 // Create this command BEFORE operation.
 public CommandChangeState(GraphicsList graphicsList)
 {
     // Keep objects state before operation.
     FillList(graphicsList, ref listBefore);
 }
Ejemplo n.º 37
0
 public override void Redo(GraphicsList list)
 {
     // Replace all objects in the list with objects from listAfter
     ReplaceObjects(list, listAfter);
 }
Ejemplo n.º 38
0
 // Call this function AFTER operation.
 public void NewState(GraphicsList graphicsList)
 {
     // Keep objects state after operation.
     FillList(graphicsList, ref listAfter);
 }
Ejemplo n.º 39
0
 // This function is used to make Undo operation.
 // It makes action opposite to the original command.
 public abstract void Undo(GraphicsList list);
Ejemplo n.º 40
0
 public override void Redo(GraphicsList list)
 {
     // Replace all objects in the list with objects from listAfter
     ReplaceObjects(list, listAfter);
 }
Ejemplo n.º 41
0
        public UndoManager(GraphicsList graphicsList)
        {
            this.graphicsList = graphicsList;

            ClearHistory();
        }
Ejemplo n.º 42
0
 public override void Undo(GraphicsList list)
 {
     list.DeleteLastAddedObject();
 }
Ejemplo n.º 43
0
 public override void Redo(GraphicsList list)
 {
     // Clear list - make DeleteAll again
     list.Clear();
 }
Ejemplo n.º 44
0
 public override void Redo(GraphicsList list)
 {
     list.UnselectAll();
     list.Add(drawObject);
 }
Ejemplo n.º 45
0
 // Call this function AFTER operation.
 public void NewState(GraphicsList graphicsList)
 {
     // Keep objects state after operation.
     FillList(graphicsList, ref listAfter);
 }