CommandDelete.cs
上传用户:sxsgcs
上传日期:2013-10-21
资源大小:110k
文件大小:2k
源码类别:

CAD

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace DrawTools
  5. {
  6.     /// <summary>
  7.     /// Delete command
  8.     /// </summary>
  9.     class CommandDelete : Command
  10.     {
  11.         List<DrawObject> cloneList;    // contains selected items which are deleted
  12.         // Create this command BEFORE applying Delete All function.
  13.         public CommandDelete(GraphicsList graphicsList)
  14.         {
  15.             cloneList = new List<DrawObject>();
  16.             // Make clone of the list selection.
  17.             foreach(DrawObject o in graphicsList.Selection)
  18.             {
  19.                 cloneList.Add(o.Clone());
  20.             }
  21.         }
  22.         public override void Undo(GraphicsList list)
  23.         {
  24.             list.UnselectAll();
  25.             // Add all objects from cloneList to list.
  26.             foreach(DrawObject o in cloneList)
  27.             {
  28.                 list.Add(o);
  29.             }
  30.         }
  31.         public override void Redo(GraphicsList list)
  32.         {
  33.             // Delete from list all objects kept in cloneList
  34.             
  35.             int n = list.Count;
  36.             for ( int i = n - 1; i >= 0; i-- )
  37.             {
  38.                 bool toDelete = false;
  39.                 DrawObject objectToDelete = list[i];
  40.                 foreach(DrawObject o in cloneList)
  41.                 {
  42.                     if ( objectToDelete.ID == o.ID )
  43.                     {
  44.                         toDelete = true;
  45.                         break;
  46.                     }
  47.                 }
  48.                 if ( toDelete )
  49.                 {
  50.                     list.RemoveAt(i);
  51.                 }
  52.             }
  53.         }
  54.     }
  55. }