|
@@ -7,6 +7,7 @@ using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows.Forms;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
|
@@ -19,47 +20,88 @@ namespace SketchAssistant
|
|
|
public Form1()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
+ fileImporter = new FileImporter(this);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public enum ProgramState
|
|
|
{
|
|
|
Idle,
|
|
|
Draw,
|
|
|
Delete
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private ProgramState currentState;
|
|
|
-
|
|
|
- OpenFileDialog openFileDialogLeft = new OpenFileDialog();
|
|
|
-
|
|
|
- Image leftImage = null;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private FileImporter fileImporter;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Image leftImage = null;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<Line> leftLineList;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
Image rightImage = null;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
List<Point> currentLine;
|
|
|
-
|
|
|
- List<Tuple<bool,Line>> lineList = new List<Tuple<bool, Line>>();
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ List<Tuple<bool,Line>> rightLineList = new List<Tuple<bool, Line>>();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
bool mousePressed = false;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
Point currentCursorPosition;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
Point previousCursorPosition;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
Queue<Point> cursorPositions = new Queue<Point>();
|
|
|
-
|
|
|
- Graphics graph = null;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Graphics rightGraph = null;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
bool[,] isFilledMatrix;
|
|
|
HashSet<int>[,] linesMatrix;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
uint deletionSize = 2;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
ActionHistory historyOfActions;
|
|
|
|
|
|
|
|
@@ -83,11 +125,11 @@ namespace SketchAssistant
|
|
|
|
|
|
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;
|
|
|
|
|
|
this.Refresh();
|
|
@@ -95,6 +137,29 @@ namespace SketchAssistant
|
|
|
UpdateButtonStatus();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private void drawButton_Click(object sender, EventArgs e)
|
|
|
{
|
|
@@ -214,8 +279,8 @@ namespace SketchAssistant
|
|
|
mousePressed = false;
|
|
|
if (currentState.Equals(ProgramState.Draw) && currentLine.Count > 0)
|
|
|
{
|
|
|
- Line newLine = new Line(currentLine, lineList.Count);
|
|
|
- lineList.Add(new Tuple<bool, Line>(true, newLine));
|
|
|
+ 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()));
|
|
|
}
|
|
@@ -233,21 +298,21 @@ namespace SketchAssistant
|
|
|
"Attention", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
|
|
|
{
|
|
|
historyOfActions = new ActionHistory(lastActionTakenLabel);
|
|
|
- DrawEmptyCanvas();
|
|
|
+ DrawEmptyCanvasRight();
|
|
|
|
|
|
isFilledMatrix = new bool[rightImage.Width, rightImage.Height];
|
|
|
linesMatrix = new HashSet<int>[rightImage.Width, rightImage.Height];
|
|
|
- lineList = new List<Tuple<bool, Line>>();
|
|
|
+ rightLineList = new List<Tuple<bool, Line>>();
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
historyOfActions = new ActionHistory(lastActionTakenLabel);
|
|
|
- DrawEmptyCanvas();
|
|
|
+ DrawEmptyCanvasRight();
|
|
|
|
|
|
isFilledMatrix = new bool[rightImage.Width, rightImage.Height];
|
|
|
linesMatrix = new HashSet<int>[rightImage.Width, rightImage.Height];
|
|
|
- lineList = new List<Tuple<bool, Line>>();
|
|
|
+ rightLineList = new List<Tuple<bool, Line>>();
|
|
|
}
|
|
|
UpdateButtonStatus();
|
|
|
}
|
|
@@ -261,7 +326,7 @@ namespace SketchAssistant
|
|
|
{
|
|
|
currentLine.Add(currentCursorPosition);
|
|
|
Line drawline = new Line(currentLine);
|
|
|
- drawline.DrawLine(graph);
|
|
|
+ drawline.DrawLine(rightGraph);
|
|
|
pictureBoxRight.Image = rightImage;
|
|
|
}
|
|
|
if (currentState.Equals(ProgramState.Delete) && mousePressed)
|
|
@@ -275,7 +340,7 @@ namespace SketchAssistant
|
|
|
historyOfActions.AddNewAction(new SketchAction(SketchAction.ActionType.Delete, linesToDelete));
|
|
|
foreach (int lineID in linesToDelete)
|
|
|
{
|
|
|
- lineList[lineID] = new Tuple<bool, Line>(false, lineList[lineID].Item2);
|
|
|
+ rightLineList[lineID] = new Tuple<bool, Line>(false, rightLineList[lineID].Item2);
|
|
|
}
|
|
|
RepopulateDeletionMatrixes();
|
|
|
RedrawRightImage();
|
|
@@ -291,37 +356,59 @@ namespace SketchAssistant
|
|
|
|
|
|
|
|
|
|
|
|
- private void DrawEmptyCanvas()
|
|
|
+ private void DrawEmptyCanvasRight()
|
|
|
{
|
|
|
if (leftImage == null)
|
|
|
{
|
|
|
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;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
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;
|
|
|
}
|
|
|
this.Refresh();
|
|
|
pictureBoxRight.Refresh();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
private void RedrawRightImage()
|
|
|
{
|
|
|
- DrawEmptyCanvas();
|
|
|
- foreach (Tuple<bool, Line> lineBoolTuple in lineList)
|
|
|
+ DrawEmptyCanvasRight();
|
|
|
+ foreach (Tuple<bool, Line> lineBoolTuple in rightLineList)
|
|
|
{
|
|
|
if (lineBoolTuple.Item1)
|
|
|
{
|
|
|
- lineBoolTuple.Item2.DrawLine(graph);
|
|
|
+ lineBoolTuple.Item2.DrawLine(rightGraph);
|
|
|
}
|
|
|
}
|
|
|
pictureBoxRight.Refresh();
|
|
@@ -336,9 +423,9 @@ namespace SketchAssistant
|
|
|
{
|
|
|
foreach (int lineId in lines)
|
|
|
{
|
|
|
- if (lineId <= lineList.Count - 1 && lineId >= 0)
|
|
|
+ if (lineId <= rightLineList.Count - 1 && lineId >= 0)
|
|
|
{
|
|
|
- lineList[lineId] = new Tuple<bool, Line>(shown, lineList[lineId].Item2);
|
|
|
+ rightLineList[lineId] = new Tuple<bool, Line>(shown, rightLineList[lineId].Item2);
|
|
|
}
|
|
|
}
|
|
|
RedrawRightImage();
|
|
@@ -443,7 +530,7 @@ namespace SketchAssistant
|
|
|
{
|
|
|
isFilledMatrix = new bool[rightImage.Width,rightImage.Height];
|
|
|
linesMatrix = new HashSet<int>[rightImage.Width, rightImage.Height];
|
|
|
- foreach(Tuple<bool,Line> lineTuple in lineList)
|
|
|
+ foreach(Tuple<bool,Line> lineTuple in rightLineList)
|
|
|
{
|
|
|
if (lineTuple.Item1)
|
|
|
{
|
|
@@ -486,5 +573,51 @@ namespace SketchAssistant
|
|
|
}
|
|
|
return returnSet;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void BindAndDrawLeftImage(List<Line> newTemplatePicture)
|
|
|
+ {
|
|
|
+ leftLineList = newTemplatePicture;
|
|
|
+ foreach(Line l in leftLineList)
|
|
|
+ {
|
|
|
+ l.DrawLine(Graphics.FromImage(leftImage));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void ShowInfoMessage(String message)
|
|
|
+ {
|
|
|
+ MessageBox.Show(message);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public Object[] GetAllVariables()
|
|
|
+ {
|
|
|
+ return new Object[] { currentState, fileImporter, openFileDialog, leftImage, leftLineList, rightImage, currentLine, rightLineList, mousePressed, currentCursorPosition, previousCursorPosition, cursorPositions, rightGraph, isFilledMatrix, linesMatrix, deletionSize, historyOfActions };
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void CreateCanvasAndSetPictureForTesting(int width, int height, List<Line> newImage)
|
|
|
+ {
|
|
|
+ DrawEmptyCanvasLeft(width, height);
|
|
|
+ BindAndDrawLeftImage(newImage);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|