SketchAction.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace SketchAssistantWPF
  7. {
  8. public class SketchAction
  9. {
  10. //Types of possible actions
  11. public enum ActionType
  12. {
  13. Draw,
  14. Delete,
  15. Start
  16. }
  17. //Type of this action
  18. private ActionType thisAction;
  19. //ID of the Line affected
  20. private HashSet<int> lineIDs;
  21. /// <summary>
  22. /// Constructor for a new action with multiple lines affected.
  23. /// </summary>
  24. /// <param name="theAction">The type of action, if it is ActionType.Start the affectedIDs will be ignored.</param>
  25. /// <param name="affectedID">The IDs of the lines affected.</param>
  26. public SketchAction(ActionType theAction, HashSet<int> affectedIDs)
  27. {
  28. thisAction = theAction;
  29. if (theAction.Equals(ActionType.Start)) { lineIDs = new HashSet<int>(); }
  30. else { lineIDs = new HashSet<int>(affectedIDs); }
  31. }
  32. /// <summary>
  33. /// Constructor for a new action with one line affected.
  34. /// </summary>
  35. /// <param name="theAction">The type of action, if it is ActionType.Start the affectedID will be ignored.</param>
  36. /// <param name="affectedID">The ID of the affected line.</param>
  37. public SketchAction(ActionType theAction, int affectedID)
  38. {
  39. thisAction = theAction;
  40. if (theAction.Equals(ActionType.Start)) { lineIDs = new HashSet<int>(); }
  41. else
  42. {
  43. lineIDs = new HashSet<int>();
  44. lineIDs.Add(affectedID);
  45. }
  46. }
  47. /// <summary>
  48. /// Fetches the type of this action.
  49. /// </summary>
  50. /// <returns>The type of this action.</returns>
  51. public ActionType GetActionType()
  52. {
  53. return thisAction;
  54. }
  55. /// <summary>
  56. /// Fetches the IDs of the lines affected by this action.
  57. /// </summary>
  58. /// <returns>The IDs of the lines affected by this action. An empty set if there is no line affected.</returns>
  59. public HashSet<int> GetLineIDs()
  60. {
  61. return lineIDs;
  62. }
  63. /// <summary>
  64. /// Get the information about this action.
  65. /// </summary>
  66. /// <returns>A String describing what happend at this action.</returns>
  67. public String GetActionInformation()
  68. {
  69. String returnString;
  70. switch (thisAction)
  71. {
  72. case ActionType.Start:
  73. returnString = "A new canvas was created.";
  74. break;
  75. case ActionType.Draw:
  76. returnString = "Line number " + lineIDs.First().ToString() + " was drawn.";
  77. break;
  78. case ActionType.Delete:
  79. if (lineIDs.Count == 1) { returnString = "Line number " + lineIDs.First().ToString() + " was deleted."; }
  80. else
  81. {
  82. returnString = "Several Lines were deleted.";
  83. }
  84. break;
  85. default:
  86. returnString = "There is no information available for this action.";
  87. break;
  88. }
  89. return returnString;
  90. }
  91. }
  92. }