|
@@ -7,6 +7,7 @@ using System.Linq;
|
|
using System.Text;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Forms;
|
|
|
|
+using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
// This is the code for your desktop app.
|
|
// This is the code for your desktop app.
|
|
@@ -19,36 +20,89 @@ namespace SketchAssistant
|
|
public Form1()
|
|
public Form1()
|
|
{
|
|
{
|
|
InitializeComponent();
|
|
InitializeComponent();
|
|
|
|
+ fileImporter = new FileImporter(this);
|
|
}
|
|
}
|
|
|
|
|
|
/**********************************/
|
|
/**********************************/
|
|
/*** CLASS VARIABLES START HERE ***/
|
|
/*** CLASS VARIABLES START HERE ***/
|
|
/**********************************/
|
|
/**********************************/
|
|
|
|
|
|
- //Different Program States
|
|
|
|
|
|
+ //important: add new variables only at the end of the list to keep the order of definition consistent with the order in which they are returned by GetAllVariables()
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Different Program States
|
|
|
|
+ /// </summary>
|
|
public enum ProgramState
|
|
public enum ProgramState
|
|
{
|
|
{
|
|
Idle,
|
|
Idle,
|
|
- Draw
|
|
|
|
|
|
+ Draw,
|
|
|
|
+ Delete
|
|
}
|
|
}
|
|
- //Current Program State
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Current Program State
|
|
|
|
+ /// </summary>
|
|
private ProgramState currentState;
|
|
private ProgramState currentState;
|
|
- //Dialog to select a file.
|
|
|
|
- OpenFileDialog openFileDialogLeft = new OpenFileDialog();
|
|
|
|
- //Image loaded on the left
|
|
|
|
- Image leftImage = null;
|
|
|
|
- //Image on the right
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// instance of FileImporter to handle drawing imports
|
|
|
|
+ /// </summary>
|
|
|
|
+ private FileImporter fileImporter;
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Dialog to select a file.
|
|
|
|
+ /// </summary>
|
|
|
|
+ OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Image loaded on the left
|
|
|
|
+ /// </summary>
|
|
|
|
+ private Image leftImage = null;
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// the graphic shown in the left window, represented as a list of polylines
|
|
|
|
+ /// </summary>
|
|
|
|
+ private List<Line> leftLineList;
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Image on the right
|
|
|
|
+ /// </summary>
|
|
Image rightImage = null;
|
|
Image rightImage = null;
|
|
- //Current Line being Drawn
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Current Line being Drawn
|
|
|
|
+ /// </summary>
|
|
List<Point> currentLine;
|
|
List<Point> currentLine;
|
|
- //All Lines in the current session
|
|
|
|
- List<Tuple<bool,Line>> lineList = new List<Tuple<bool, Line>>();
|
|
|
|
- //Whether the Mouse is currently pressed in the rightPictureBox
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// All Lines in the current session
|
|
|
|
+ /// </summary>
|
|
|
|
+ List<Tuple<bool,Line>> rightLineList = new List<Tuple<bool, Line>>();
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Whether the Mouse is currently pressed in the rightPictureBox
|
|
|
|
+ /// </summary>
|
|
bool mousePressed = false;
|
|
bool mousePressed = false;
|
|
- //The Position of the Cursor in the right picture box
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// The Position of the Cursor in the right picture box
|
|
|
|
+ /// </summary>
|
|
Point currentCursorPosition;
|
|
Point currentCursorPosition;
|
|
- //The graphic representation of the right image
|
|
|
|
- Graphics graph = null;
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// The Previous Cursor Position in the right picture box
|
|
|
|
+ /// </summary>
|
|
|
|
+ Point previousCursorPosition;
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Queue for the cursorPositions
|
|
|
|
+ /// </summary>
|
|
|
|
+ Queue<Point> cursorPositions = new Queue<Point>();
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// The graphic representation of the right image
|
|
|
|
+ /// </summary>
|
|
|
|
+ Graphics rightGraph = null;
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Deletion Matrixes for checking postions of lines in the image
|
|
|
|
+ /// </summary>
|
|
|
|
+ bool[,] isFilledMatrix;
|
|
|
|
+ HashSet<int>[,] linesMatrix;
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Size of deletion area
|
|
|
|
+ /// </summary>
|
|
|
|
+ uint deletionSize = 2;
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// History of Actions
|
|
|
|
+ /// </summary>
|
|
|
|
+ ActionHistory historyOfActions;
|
|
|
|
|
|
/******************************************/
|
|
/******************************************/
|
|
/*** FORM SPECIFIC FUNCTIONS START HERE ***/
|
|
/*** FORM SPECIFIC FUNCTIONS START HERE ***/
|
|
@@ -58,6 +112,8 @@ namespace SketchAssistant
|
|
{
|
|
{
|
|
currentState = ProgramState.Idle;
|
|
currentState = ProgramState.Idle;
|
|
this.DoubleBuffered = true;
|
|
this.DoubleBuffered = true;
|
|
|
|
+ historyOfActions = new ActionHistory(null);
|
|
|
|
+ UpdateButtonStatus();
|
|
}
|
|
}
|
|
|
|
|
|
//Resize Function connected to the form resize event, will refresh the form when it is resized
|
|
//Resize Function connected to the form resize event, will refresh the form when it is resized
|
|
@@ -69,18 +125,42 @@ namespace SketchAssistant
|
|
//Load button, will open an OpenFileDialog
|
|
//Load button, will open an OpenFileDialog
|
|
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
|
|
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
{
|
|
- openFileDialogLeft.Filter = "Image|*.jpg;*.png;*.jpeg";
|
|
|
|
- if(openFileDialogLeft.ShowDialog() == DialogResult.OK)
|
|
|
|
|
|
+ openFileDialog.Filter = "Image|*.jpg;*.png;*.jpeg";
|
|
|
|
+ if(openFileDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
{
|
|
- toolStripLoadStatus.Text = openFileDialogLeft.SafeFileName;
|
|
|
|
- leftImage = Image.FromFile(openFileDialogLeft.FileName);
|
|
|
|
|
|
+ toolStripLoadStatus.Text = openFileDialog.SafeFileName;
|
|
|
|
+ leftImage = Image.FromFile(openFileDialog.FileName);
|
|
pictureBoxLeft.Image = leftImage;
|
|
pictureBoxLeft.Image = leftImage;
|
|
//Refresh the left image box when the content is changed
|
|
//Refresh the left image box when the content is changed
|
|
this.Refresh();
|
|
this.Refresh();
|
|
}
|
|
}
|
|
|
|
+ UpdateButtonStatus();
|
|
}
|
|
}
|
|
|
|
|
|
- //Changes The State of the Program to drawing
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Import button, will open an OpenFileDialog
|
|
|
|
+ /// </summary>
|
|
|
|
+ private void examplePictureToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
+ {
|
|
|
|
+ openFileDialog.Filter = "Interactive Sketch-Assistant Drawing|*.isad";
|
|
|
|
+ if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
+ {
|
|
|
|
+ toolStripLoadStatus.Text = openFileDialog.SafeFileName;
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ (int, int, List<Line>) values = fileImporter.ParseISADInputFile(openFileDialog.FileName);
|
|
|
|
+ DrawEmptyCanvasLeft(values.Item1, values.Item2);
|
|
|
|
+ BindAndDrawLeftImage(values.Item3);
|
|
|
|
+ this.Refresh();
|
|
|
|
+ }
|
|
|
|
+ catch(FileImporterException ex)
|
|
|
|
+ {
|
|
|
|
+ ShowInfoMessage(ex.ToString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //Changes the state of the program to drawing
|
|
private void drawButton_Click(object sender, EventArgs e)
|
|
private void drawButton_Click(object sender, EventArgs e)
|
|
{
|
|
{
|
|
if(rightImage != null)
|
|
if(rightImage != null)
|
|
@@ -94,6 +174,87 @@ namespace SketchAssistant
|
|
ChangeState(ProgramState.Draw);
|
|
ChangeState(ProgramState.Draw);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ UpdateButtonStatus();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //Changes the state of the program to deletion
|
|
|
|
+ private void deleteButton_Click(object sender, EventArgs e)
|
|
|
|
+ {
|
|
|
|
+ if (rightImage != null)
|
|
|
|
+ {
|
|
|
|
+ if (currentState.Equals(ProgramState.Delete))
|
|
|
|
+ {
|
|
|
|
+ ChangeState(ProgramState.Idle);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ ChangeState(ProgramState.Delete);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ UpdateButtonStatus();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //Undo an action
|
|
|
|
+ private void undoButton_Click(object sender, EventArgs e)
|
|
|
|
+ {
|
|
|
|
+ if (historyOfActions.CanUndo())
|
|
|
|
+ {
|
|
|
|
+ HashSet<int> affectedLines = historyOfActions.GetCurrentAction().GetLineIDs();
|
|
|
|
+ SketchAction.ActionType undoAction = historyOfActions.GetCurrentAction().GetActionType();
|
|
|
|
+ switch (undoAction)
|
|
|
|
+ {
|
|
|
|
+ case SketchAction.ActionType.Delete:
|
|
|
|
+ //Deleted Lines need to be shown
|
|
|
|
+ ChangeLines(affectedLines, true);
|
|
|
|
+ break;
|
|
|
|
+ case SketchAction.ActionType.Draw:
|
|
|
|
+ //Drawn lines need to be hidden
|
|
|
|
+ ChangeLines(affectedLines, false);
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ historyOfActions.MoveAction(true);
|
|
|
|
+ UpdateButtonStatus();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //Redo an action
|
|
|
|
+ private void redoButton_Click(object sender, EventArgs e)
|
|
|
|
+ {
|
|
|
|
+ if (historyOfActions.CanRedo())
|
|
|
|
+ {
|
|
|
|
+ historyOfActions.MoveAction(false);
|
|
|
|
+ HashSet<int> affectedLines = historyOfActions.GetCurrentAction().GetLineIDs();
|
|
|
|
+ SketchAction.ActionType redoAction = historyOfActions.GetCurrentAction().GetActionType();
|
|
|
|
+ switch (redoAction)
|
|
|
|
+ {
|
|
|
|
+ case SketchAction.ActionType.Delete:
|
|
|
|
+ //Deleted Lines need to be redeleted
|
|
|
|
+ ChangeLines(affectedLines, false);
|
|
|
|
+ break;
|
|
|
|
+ case SketchAction.ActionType.Draw:
|
|
|
|
+ //Drawn lines need to be redrawn
|
|
|
|
+ ChangeLines(affectedLines, true);
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ UpdateButtonStatus();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //Detect Keyboard Shortcuts
|
|
|
|
+ private void Form1_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Z)
|
|
|
|
+ {
|
|
|
|
+ undoButton_Click(sender, e);
|
|
|
|
+ }
|
|
|
|
+ if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Y)
|
|
|
|
+ {
|
|
|
|
+ redoButton_Click(sender, e);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
//get current Mouse positon within the right picture box
|
|
//get current Mouse positon within the right picture box
|
|
@@ -112,14 +273,18 @@ namespace SketchAssistant
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- //Lift left mouse button to stop drawing.
|
|
|
|
|
|
+ //Lift left mouse button to stop drawing and add a new Line.
|
|
private void pictureBoxRight_MouseUp(object sender, MouseEventArgs e)
|
|
private void pictureBoxRight_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
{
|
|
mousePressed = false;
|
|
mousePressed = false;
|
|
- if (currentState.Equals(ProgramState.Draw))
|
|
|
|
|
|
+ if (currentState.Equals(ProgramState.Draw) && currentLine.Count > 0)
|
|
{
|
|
{
|
|
- lineList.Add(new Tuple<bool, Line>(true, new Line(currentLine)));
|
|
|
|
|
|
+ Line newLine = new Line(currentLine, rightLineList.Count);
|
|
|
|
+ rightLineList.Add(new Tuple<bool, Line>(true, newLine));
|
|
|
|
+ newLine.PopulateMatrixes(isFilledMatrix, linesMatrix);
|
|
|
|
+ historyOfActions.AddNewAction(new SketchAction(SketchAction.ActionType.Draw, newLine.GetID()));
|
|
}
|
|
}
|
|
|
|
+ UpdateButtonStatus();
|
|
}
|
|
}
|
|
|
|
|
|
//Button to create a new Canvas. Will create an empty image
|
|
//Button to create a new Canvas. Will create an empty image
|
|
@@ -127,19 +292,61 @@ namespace SketchAssistant
|
|
//If there is no image loaded the canvas will be the size of the right picture box
|
|
//If there is no image loaded the canvas will be the size of the right picture box
|
|
private void canvasButton_Click(object sender, EventArgs e)
|
|
private void canvasButton_Click(object sender, EventArgs e)
|
|
{
|
|
{
|
|
- DrawEmptyCanvas();
|
|
|
|
|
|
+ if (!historyOfActions.IsEmpty())
|
|
|
|
+ {
|
|
|
|
+ if (MessageBox.Show("You have unsaved changes, creating a new canvas will discard these.",
|
|
|
|
+ "Attention", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
|
|
|
|
+ {
|
|
|
|
+ historyOfActions = new ActionHistory(lastActionTakenLabel);
|
|
|
|
+ DrawEmptyCanvasRight();
|
|
|
|
+ //The following lines cannot be in DrawEmptyCanvas()
|
|
|
|
+ isFilledMatrix = new bool[rightImage.Width, rightImage.Height];
|
|
|
|
+ linesMatrix = new HashSet<int>[rightImage.Width, rightImage.Height];
|
|
|
|
+ rightLineList = new List<Tuple<bool, Line>>();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ historyOfActions = new ActionHistory(lastActionTakenLabel);
|
|
|
|
+ DrawEmptyCanvasRight();
|
|
|
|
+ //The following lines cannot be in DrawEmptyCanvas()
|
|
|
|
+ isFilledMatrix = new bool[rightImage.Width, rightImage.Height];
|
|
|
|
+ linesMatrix = new HashSet<int>[rightImage.Width, rightImage.Height];
|
|
|
|
+ rightLineList = new List<Tuple<bool, Line>>();
|
|
|
|
+ }
|
|
|
|
+ UpdateButtonStatus();
|
|
}
|
|
}
|
|
|
|
|
|
//add a Point on every tick to the Drawpath
|
|
//add a Point on every tick to the Drawpath
|
|
- private void drawTimer_Tick(object sender, EventArgs e)
|
|
|
|
|
|
+ private void mouseTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
{
|
|
|
|
+ cursorPositions.Enqueue(currentCursorPosition);
|
|
|
|
+ previousCursorPosition = cursorPositions.Dequeue();
|
|
if (currentState.Equals(ProgramState.Draw) && mousePressed)
|
|
if (currentState.Equals(ProgramState.Draw) && mousePressed)
|
|
{
|
|
{
|
|
currentLine.Add(currentCursorPosition);
|
|
currentLine.Add(currentCursorPosition);
|
|
Line drawline = new Line(currentLine);
|
|
Line drawline = new Line(currentLine);
|
|
- drawline.DrawLine(graph);
|
|
|
|
|
|
+ drawline.DrawLine(rightGraph);
|
|
pictureBoxRight.Image = rightImage;
|
|
pictureBoxRight.Image = rightImage;
|
|
}
|
|
}
|
|
|
|
+ if (currentState.Equals(ProgramState.Delete) && mousePressed)
|
|
|
|
+ {
|
|
|
|
+ List<Point> uncheckedPoints = Line.BresenhamLineAlgorithm(previousCursorPosition, currentCursorPosition);
|
|
|
|
+ foreach (Point currPoint in uncheckedPoints)
|
|
|
|
+ {
|
|
|
|
+ HashSet<int> linesToDelete = CheckDeletionMatrixesAroundPoint(currPoint, deletionSize);
|
|
|
|
+ if (linesToDelete.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ historyOfActions.AddNewAction(new SketchAction(SketchAction.ActionType.Delete, linesToDelete));
|
|
|
|
+ foreach (int lineID in linesToDelete)
|
|
|
|
+ {
|
|
|
|
+ rightLineList[lineID] = new Tuple<bool, Line>(false, rightLineList[lineID].Item2);
|
|
|
|
+ }
|
|
|
|
+ RepopulateDeletionMatrixes();
|
|
|
|
+ RedrawRightImage();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/***********************************/
|
|
/***********************************/
|
|
@@ -149,39 +356,90 @@ namespace SketchAssistant
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Creates an empty Canvas
|
|
/// Creates an empty Canvas
|
|
/// </summary>
|
|
/// </summary>
|
|
- private void DrawEmptyCanvas()
|
|
|
|
|
|
+ private void DrawEmptyCanvasRight()
|
|
{
|
|
{
|
|
if (leftImage == null)
|
|
if (leftImage == null)
|
|
{
|
|
{
|
|
rightImage = new Bitmap(pictureBoxRight.Width, pictureBoxRight.Height);
|
|
rightImage = new Bitmap(pictureBoxRight.Width, pictureBoxRight.Height);
|
|
- graph = Graphics.FromImage(rightImage);
|
|
|
|
- graph.FillRectangle(Brushes.White, 0, 0, pictureBoxRight.Width + 10, pictureBoxRight.Height + 10);
|
|
|
|
|
|
+ rightGraph = Graphics.FromImage(rightImage);
|
|
|
|
+ rightGraph.FillRectangle(Brushes.White, 0, 0, pictureBoxRight.Width + 10, pictureBoxRight.Height + 10);
|
|
pictureBoxRight.Image = rightImage;
|
|
pictureBoxRight.Image = rightImage;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
rightImage = new Bitmap(leftImage.Width, leftImage.Height);
|
|
rightImage = new Bitmap(leftImage.Width, leftImage.Height);
|
|
- graph = Graphics.FromImage(rightImage);
|
|
|
|
- graph.FillRectangle(Brushes.White, 0, 0, leftImage.Width + 10, leftImage.Height + 10);
|
|
|
|
|
|
+ rightGraph = Graphics.FromImage(rightImage);
|
|
|
|
+ rightGraph.FillRectangle(Brushes.White, 0, 0, leftImage.Width + 10, leftImage.Height + 10);
|
|
pictureBoxRight.Image = rightImage;
|
|
pictureBoxRight.Image = rightImage;
|
|
}
|
|
}
|
|
this.Refresh();
|
|
this.Refresh();
|
|
pictureBoxRight.Refresh();
|
|
pictureBoxRight.Refresh();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Creates an empty Canvas on the left
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="width"> width of the new canvas in pixels </param>
|
|
|
|
+ /// <param name="height"> height of the new canvas in pixels </param>
|
|
|
|
+ private void DrawEmptyCanvasLeft(int width, int height)
|
|
|
|
+ {
|
|
|
|
+ if (width == 0)
|
|
|
|
+ {
|
|
|
|
+ leftImage = new Bitmap(pictureBoxLeft.Width, pictureBoxLeft.Height);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ leftImage = new Bitmap(width, height);
|
|
|
|
+ }
|
|
|
|
+ Graphics.FromImage(leftImage).FillRectangle(Brushes.White, 0, 0, pictureBoxLeft.Width + 10, pictureBoxLeft.Height + 10);
|
|
|
|
+ pictureBoxLeft.Image = leftImage;
|
|
|
|
+
|
|
|
|
+ this.Refresh();
|
|
|
|
+ pictureBoxLeft.Refresh();
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Redraws all lines in lineList, for which their associated boolean value equals true.
|
|
/// Redraws all lines in lineList, for which their associated boolean value equals true.
|
|
/// </summary>
|
|
/// </summary>
|
|
private void RedrawRightImage()
|
|
private void RedrawRightImage()
|
|
{
|
|
{
|
|
- DrawEmptyCanvas();
|
|
|
|
- foreach (Tuple<bool, Line> lineBoolTuple in lineList)
|
|
|
|
|
|
+ DrawEmptyCanvasRight();
|
|
|
|
+ foreach (Tuple<bool, Line> lineBoolTuple in rightLineList)
|
|
{
|
|
{
|
|
if (lineBoolTuple.Item1)
|
|
if (lineBoolTuple.Item1)
|
|
{
|
|
{
|
|
- lineBoolTuple.Item2.DrawLine(graph);
|
|
|
|
|
|
+ lineBoolTuple.Item2.DrawLine(rightGraph);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ pictureBoxRight.Refresh();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Change the status of whether or not the lines are shown.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="lines">The HashSet containing the affected Line IDs.</param>
|
|
|
|
+ /// <param name="shown">True if the lines should be shown, false if they should be hidden.</param>
|
|
|
|
+ private void ChangeLines(HashSet<int> lines, bool shown)
|
|
|
|
+ {
|
|
|
|
+ foreach (int lineId in lines)
|
|
|
|
+ {
|
|
|
|
+ if (lineId <= rightLineList.Count - 1 && lineId >= 0)
|
|
|
|
+ {
|
|
|
|
+ rightLineList[lineId] = new Tuple<bool, Line>(shown, rightLineList[lineId].Item2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ RedrawRightImage();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Updates the active status of buttons. Currently draw, delete, undo and redo button.
|
|
|
|
+ /// </summary>
|
|
|
|
+ private void UpdateButtonStatus()
|
|
|
|
+ {
|
|
|
|
+ undoButton.Enabled = historyOfActions.CanUndo();
|
|
|
|
+ redoButton.Enabled = historyOfActions.CanRedo();
|
|
|
|
+ drawButton.Enabled = (rightImage != null);
|
|
|
|
+ deleteButton.Enabled = (rightImage != null);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -195,7 +453,11 @@ namespace SketchAssistant
|
|
{
|
|
{
|
|
case ProgramState.Draw:
|
|
case ProgramState.Draw:
|
|
drawButton.CheckState = CheckState.Unchecked;
|
|
drawButton.CheckState = CheckState.Unchecked;
|
|
- drawTimer.Enabled = false;
|
|
|
|
|
|
+ mouseTimer.Enabled = false;
|
|
|
|
+ break;
|
|
|
|
+ case ProgramState.Delete:
|
|
|
|
+ deleteButton.CheckState = CheckState.Unchecked;
|
|
|
|
+ mouseTimer.Enabled = false;
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
break;
|
|
break;
|
|
@@ -204,7 +466,11 @@ namespace SketchAssistant
|
|
{
|
|
{
|
|
case ProgramState.Draw:
|
|
case ProgramState.Draw:
|
|
drawButton.CheckState = CheckState.Checked;
|
|
drawButton.CheckState = CheckState.Checked;
|
|
- drawTimer.Enabled = true;
|
|
|
|
|
|
+ mouseTimer.Enabled = true;
|
|
|
|
+ break;
|
|
|
|
+ case ProgramState.Delete:
|
|
|
|
+ deleteButton.CheckState = CheckState.Checked;
|
|
|
|
+ mouseTimer.Enabled = true;
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
break;
|
|
break;
|
|
@@ -254,5 +520,104 @@ namespace SketchAssistant
|
|
}
|
|
}
|
|
return realCoordinates;
|
|
return realCoordinates;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// A function that populates the matrixes needed for deletion detection with line data.
|
|
|
|
+ /// </summary>
|
|
|
|
+ private void RepopulateDeletionMatrixes()
|
|
|
|
+ {
|
|
|
|
+ if(rightImage != null)
|
|
|
|
+ {
|
|
|
|
+ isFilledMatrix = new bool[rightImage.Width,rightImage.Height];
|
|
|
|
+ linesMatrix = new HashSet<int>[rightImage.Width, rightImage.Height];
|
|
|
|
+ foreach(Tuple<bool,Line> lineTuple in rightLineList)
|
|
|
|
+ {
|
|
|
|
+ if (lineTuple.Item1)
|
|
|
|
+ {
|
|
|
|
+ lineTuple.Item2.PopulateMatrixes(isFilledMatrix, linesMatrix);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// A function that checks the deletion matrixes at a certain point
|
|
|
|
+ /// and returns all Line ids at that point and in a square around it in a certain range.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="p">The point around which to check.</param>
|
|
|
|
+ /// <param name="range">The range around the point. If range is 0, only the point is checked.</param>
|
|
|
|
+ /// <returns>A List of all lines.</returns>
|
|
|
|
+ private HashSet<int> CheckDeletionMatrixesAroundPoint(Point p, uint range)
|
|
|
|
+ {
|
|
|
|
+ HashSet<int> returnSet = new HashSet<int>();
|
|
|
|
+
|
|
|
|
+ if (p.X >= 0 && p.Y >= 0 && p.X < rightImage.Width && p.Y < rightImage.Height)
|
|
|
|
+ {
|
|
|
|
+ if (isFilledMatrix[p.X, p.Y])
|
|
|
|
+ {
|
|
|
|
+ returnSet.UnionWith(linesMatrix[p.X, p.Y]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (int x_mod = (int)range*(-1); x_mod < range; x_mod++)
|
|
|
|
+ {
|
|
|
|
+ for (int y_mod = (int)range * (-1); y_mod < range; y_mod++)
|
|
|
|
+ {
|
|
|
|
+ if (p.X + x_mod >= 0 && p.Y + y_mod >= 0 && p.X + x_mod < rightImage.Width && p.Y + y_mod < rightImage.Height)
|
|
|
|
+ {
|
|
|
|
+ if (isFilledMatrix[p.X + x_mod, p.Y + y_mod])
|
|
|
|
+ {
|
|
|
|
+ returnSet.UnionWith(linesMatrix[p.X + x_mod, p.Y + y_mod]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return returnSet;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// binds the given picture to templatePicture and draws it
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="newTemplatePicture"> the new template picture, represented as a list of polylines </param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ private void BindAndDrawLeftImage(List<Line> newTemplatePicture)
|
|
|
|
+ {
|
|
|
|
+ leftLineList = newTemplatePicture;
|
|
|
|
+ foreach(Line l in leftLineList)
|
|
|
|
+ {
|
|
|
|
+ l.DrawLine(Graphics.FromImage(leftImage));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// shows the given info message in a popup and asks the user to aknowledge it
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="message">the message to show</param>
|
|
|
|
+ private void ShowInfoMessage(String message)
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show(message);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// returns all instance variables in the order of their definition for testing
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <returns>all instance variables in the order of their definition</returns>
|
|
|
|
+ public Object[]/*(ProgramState, FileImporter, OpenFileDialog, Image, List<Line>, Image, List<Point>, List<Tuple<bool, Line>>, bool, Point, Point, Queue<Point>, Graphics, bool[,], HashSet<int>[,], uint, ActionHistory)*/ GetAllVariables()
|
|
|
|
+ {
|
|
|
|
+ return new Object[] { currentState, fileImporter, openFileDialog, leftImage, leftLineList, rightImage, currentLine, rightLineList, mousePressed, currentCursorPosition, previousCursorPosition, cursorPositions, rightGraph, isFilledMatrix, linesMatrix, deletionSize, historyOfActions };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// public method wrapper for testing purposes, invoking DrawEmptyCanvas(...) and BindAndDrawLeftImage(...)
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="width">width of the parsed image</param>
|
|
|
|
+ /// <param name="height">height of the parsed image</param>
|
|
|
|
+ /// <param name="newImage">the parsed image</param>
|
|
|
|
+ public void CreateCanvasAndSetPictureForTesting(int width, int height, List<Line> newImage)
|
|
|
|
+ {
|
|
|
|
+ DrawEmptyCanvasLeft(width, height);
|
|
|
|
+ BindAndDrawLeftImage(newImage);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|