Browse Source

Prepared for merge,

- Cleaned up code
- Split up Program into Model, View and Presenter
- Created MVP_View interfaced, which will be able to be used for
integration testing
- RedrawAssistant currently serves no purpose, and will be reimplemented
- File Importer test is no longer working, will have to be adapted to
fit refactoring.
Martin Edlund 5 years ago
parent
commit
4e00069237

+ 13 - 0
Finished Userstories/userstory19.md

@@ -0,0 +1,13 @@
+# Userstory 19  
+ 
+|**ID**|19|  
+|-|-|
+|**Name**|Verbesserung der Struktur des Programms|
+|**Beschreibung**|Strukturierung des Programms zu einem Model-View-Controller Modell.|
+|**Akzeptanzkriterium**|Aufteilung der Form Datei in drei Klassen: Eine View Klasse, welche Aufgaben bezüglich Anzeigen im Form übernimmt. Eine Controller Klasse, welche Eingaben vom Form empfängt und verarbeitet. Sowie eine Model Klasse, welche den Status des Programms darstellt, und vom Controller manipuliert wird und selbst den View anpasst.|
+|Geschätzter Aufwand (Story Points)|20|
+|Entwickler|Martin Edlund|
+|Umgesetzt in Iteration|6|
+|Tatsächlicher Aufwand (Std.)|8|
+|Velocity (Std./Story Point)|0,4|
+|Bemerkungen|Keine|

+ 8 - 7
SketchAssistant/SketchAssistant.Tests/UnitTest1.cs

@@ -205,11 +205,10 @@ namespace Tests
     [TestClass]
     public class ActionHistoryTests
     {
-        ToolStripStatusLabel testLabel = new ToolStripStatusLabel();
 
         private ActionHistory GetActionHistory()
         {
-            return new ActionHistory(testLabel);
+            return new ActionHistory();
         }
 
         [DataTestMethod]
@@ -267,13 +266,13 @@ namespace Tests
             Assert.AreEqual(true, testHistory.CanUndo());
             testHistory.MoveAction(true);
             Assert.AreEqual(true, testHistory.CanRedo());
-            testHistory.MoveAction(false);
+            var lastActionLabel = testHistory.MoveAction(false);
             Assert.AreEqual(actionType, testHistory.GetCurrentAction().GetActionType());
-            String currLabel = testLabel.Text;
-            Assert.AreEqual(currLabel, message);
+            Assert.AreEqual(message, lastActionLabel);
         }
     }
 
+    /*
     [TestClass]
     public class FileImporterTests
     {
@@ -284,7 +283,7 @@ namespace Tests
         public void ParseISADInputSuccessfulTest(int[] xCoordinates, int[] yCoordinates)
         {
             Form1 program = new Form1();
-            FileImporter uut = new SketchAssistant.FileImporter(program);
+            FileImporter uut = new SketchAssistant.FileImporter();
 
             List<String> file = new List<string>();
             file.Add("drawing");
@@ -369,8 +368,9 @@ namespace Tests
             //cast is save as long as Form1#GetAllVariables() is conform to its contract
             return (List<Line>)program.GetAllVariables().Find(x => x.Item1.Equals("leftLineList")).Item2;
         }
-    }
+    }*/
 
+    /*
     [TestClass]
     public class RedrawAssistantTests
     {
@@ -592,4 +592,5 @@ namespace Tests
             }
         }
     }
+    */
 }

+ 32 - 543
SketchAssistant/SketchAssistant/Form1.cs

@@ -9,13 +9,12 @@ using System.Threading.Tasks;
 using System.Windows.Forms;
 using System.Text.RegularExpressions;
 
-
 // This is the code for your desktop app.
 // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app.
 
 namespace SketchAssistant
 {
-    public partial class Form1 : Form
+    public partial class Form1 : Form, MVP_View
     {
         public Form1()
         {
@@ -138,11 +137,6 @@ namespace SketchAssistant
         private void Form1_Load(object sender, EventArgs e)
         {
             this.DoubleBuffered = true;
-            /*
-            currentState = ProgramState.Idle;
-            historyOfActions = new ActionHistory(null);
-            redrawAss = new RedrawAssistant();
-            UpdateButtonStatus();*/
         }
 
         /// <summary>
@@ -152,27 +146,12 @@ namespace SketchAssistant
         {
             ProgramPresenter.Resize(new Tuple<int, int>(pictureBoxLeft.Width, pictureBoxLeft.Height), 
                 new Tuple<int, int>(pictureBoxRight.Width, pictureBoxRight.Height));
-            /*
-            this.Refresh();
-            UpdateSizes();*/
         }
         
         //Load button, will open an OpenFileDialog
         private void loadToolStripMenuItem_Click(object sender, EventArgs e)
         {
             ProgramPresenter.LoadToolStripMenuItemClick();
-            /*
-            openFileDialog.Filter = "Image|*.jpg;*.png;*.jpeg";
-            if(openFileDialog.ShowDialog() == DialogResult.OK)
-            {
-                toolStripLoadStatus.Text = openFileDialog.SafeFileName;
-                leftImage = Image.FromFile(openFileDialog.FileName);
-                pictureBoxLeft.Image = leftImage;
-                //Refresh the left image box when the content is changed
-                this.Refresh();
-            }
-            UpdateButtonStatus();
-            */
         }
 
         /// <summary>
@@ -181,40 +160,6 @@ namespace SketchAssistant
         private void examplePictureToolStripMenuItem_Click(object sender, EventArgs e)
         {
             ProgramPresenter.ExamplePictureToolStripMenuItemClick();
-            /*
-            if (CheckSavedStatus())
-            {
-                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);
-
-                        //Match The right canvas to the left
-                        historyOfActions = new ActionHistory(lastActionTakenLabel);
-                        DrawEmptyCanvasRight();
-                        isFilledMatrix = new bool[rightImage.Width, rightImage.Height];
-                        linesMatrix = new HashSet<int>[rightImage.Width, rightImage.Height];
-                        rightLineList = new List<Tuple<bool, Line>>();
-                        //Start the redraw mode
-                        redrawAss = new RedrawAssistant(leftLineList);
-                        UpdateSizes();
-                        overlayItems = redrawAss.Tick(currentCursorPosition, rightLineList, -1, false);
-                        RedrawRightImage();
-                        this.Refresh();
-                    }
-                    catch (FileImporterException ex)
-                    {
-                        ShowInfoMessage(ex.ToString());
-                    }
-                }
-            }
-            UpdateButtonStatus();
-            */
         }
 
         /// <summary>
@@ -223,19 +168,6 @@ namespace SketchAssistant
         private void drawButton_Click(object sender, EventArgs e)
         {
             ProgramPresenter.ChangeState(true);
-            /*
-            if(rightImage != null)
-            {
-                if (currentState.Equals(ProgramState.Draw))
-                {
-                    ChangeState(ProgramState.Idle);
-                }
-                else
-                {
-                    ChangeState(ProgramState.Draw);
-                }
-            }
-            UpdateButtonStatus();*/
         }
 
         /// <summary>
@@ -244,19 +176,6 @@ namespace SketchAssistant
         private void deleteButton_Click(object sender, EventArgs e)
         {
             ProgramPresenter.ChangeState(false);
-            /*
-            if (rightImage != null)
-            {
-                if (currentState.Equals(ProgramState.Delete))
-                {
-                    ChangeState(ProgramState.Idle);
-                }
-                else
-                {
-                    ChangeState(ProgramState.Delete);
-                }
-            }
-            UpdateButtonStatus();*/
         }
 
         /// <summary>
@@ -265,29 +184,6 @@ namespace SketchAssistant
         private void undoButton_Click(object sender, EventArgs e)
         {
             ProgramPresenter.Undo();
-            /*
-            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;
-                }
-                overlayItems = redrawAss.Tick(currentCursorPosition, rightLineList, -1, false);
-                RedrawRightImage();
-            }
-            historyOfActions.MoveAction(true);
-            UpdateButtonStatus();*/
         }
 
         /// <summary>
@@ -296,29 +192,6 @@ namespace SketchAssistant
         private void redoButton_Click(object sender, EventArgs e)
         {
             ProgramPresenter.Redo();
-            /*
-            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;
-                }
-                overlayItems = redrawAss.Tick(currentCursorPosition, rightLineList, -1, false);
-                RedrawRightImage();
-            }
-            UpdateButtonStatus();*/
         }
 
         /// <summary>
@@ -342,8 +215,6 @@ namespace SketchAssistant
         private void pictureBoxRight_MouseMove(object sender, MouseEventArgs e)
         {
             ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, e);
-            
-            //currentCursorPosition = ConvertCoordinates(new Point(e.X, e.Y));
         }
         
         /// <summary>
@@ -352,12 +223,6 @@ namespace SketchAssistant
         private void pictureBoxRight_MouseDown(object sender, MouseEventArgs e)
         {
             ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Down, e);
-            /*
-            mousePressed = true;
-            if (currentState.Equals(ProgramState.Draw))
-            {
-                currentLine = new List<Point>();
-            }*/
         }
         
         /// <summary>
@@ -366,19 +231,6 @@ namespace SketchAssistant
         private void pictureBoxRight_MouseUp(object sender, MouseEventArgs e)
         {
             ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up, e);
-            /*
-            mousePressed = false;
-            if (currentState.Equals(ProgramState.Draw) && currentLine.Count > 0)
-            {
-                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()));
-                //Execute a RedrawAssistant tick with the currently finished Line
-                overlayItems = redrawAss.Tick(currentCursorPosition, rightLineList, newLine.GetID(), true);
-                RedrawRightImage();
-            }
-            UpdateButtonStatus();*/
         }
         
         /// <summary>
@@ -389,26 +241,6 @@ namespace SketchAssistant
         private void canvasButton_Click(object sender, EventArgs e)
         {
             ProgramPresenter.NewCanvas();
-            /*
-            if (CheckSavedStatus())
-            {
-                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>>();
-                //Reinitialise the Redraw Assistant.
-                if(leftLineList != null)
-                {
-                    redrawAss = new RedrawAssistant(leftLineList);
-                    UpdateSizes();
-                    overlayItems = redrawAss.Tick(currentCursorPosition, rightLineList, -1, false);
-                    RedrawRightImage();
-                }
-            }
-            UpdateButtonStatus();
-            UpdateSizes();*/
         }
 
         /// <summary>
@@ -418,49 +250,15 @@ namespace SketchAssistant
         private void mouseTimer_Tick(object sender, EventArgs e)
         {
             ProgramPresenter.Tick();
-            /*
-            if(cursorPositions.Count > 0) { previousCursorPosition = cursorPositions.Dequeue(); }
-            else { previousCursorPosition = currentCursorPosition; }
-            cursorPositions.Enqueue(currentCursorPosition);
-            //Drawing
-            if (currentState.Equals(ProgramState.Draw) && mousePressed)
-            {
-                rightGraph = Graphics.FromImage(rightImage);
-                currentLine.Add(currentCursorPosition);
-                Line drawline = new Line(currentLine);
-                drawline.DrawLine(rightGraph);
-                pictureBoxRight.Image = rightImage;
-                //Redraw overlay gets ticked
-                overlayItems = redrawAss.Tick(currentCursorPosition, rightLineList, rightLineList.Count, false);
-                RedrawRightImage();
-            }
-            //Deleting
-            if (currentState.Equals(ProgramState.Delete) && mousePressed)
-            {
-                List<Point> uncheckedPoints = GeometryCalculator.BresenhamLineAlgorithm(previousCursorPosition, currentCursorPosition);
-                foreach (Point currPoint in uncheckedPoints)
-                {
-                    HashSet<int> linesToDelete = CheckDeletionMatrixesAroundPoint(currPoint, deletionRadius);
-                    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();
-                        //Redraw overlay gets ticked
-                        overlayItems = redrawAss.Tick(currentCursorPosition, rightLineList, -1, false);
-                        RedrawRightImage();
-                    }
-                }
-            }*/
         }
 
         /*************************/
         /*** PRESENTER -> VIEW ***/
         /*************************/
 
+        /// <summary>
+        /// Enables the timer of the View, which will tick the Presenter.
+        /// </summary>
         public void EnableTimer()
         {
             mouseTimer.Enabled = true;
@@ -485,16 +283,29 @@ namespace SketchAssistant
             }
         }
 
+        /// <summary>
+        /// Sets the contents of the load status indicator label.
+        /// </summary>
+        /// <param name="message">The new contents</param>
         public void SetToolStripLoadStatus(String message)
         {
             toolStripLoadStatus.Text = message;
         }
 
+        /// <summary>
+        /// Sets the contents of the last action taken indicator label.
+        /// </summary>
+        /// <param name="message">The new contents</param>
         public void SetLastActionTakenText(String message)
         {
             lastActionTakenLabel.Text = message;
         }
 
+        /// <summary>
+        /// Changes the states of a tool strip button.
+        /// </summary>
+        /// <param name="buttonName">The name of the button.</param>
+        /// <param name="state">The new state of the button.</param>
         public void SetToolStripButtonStatus(String buttonName, ButtonState state)
         {
             ToolStripButton buttonToChange;
@@ -535,12 +346,20 @@ namespace SketchAssistant
             }
         }
 
+        /// <summary>
+        /// Displays an image in the left Picture box.
+        /// </summary>
+        /// <param name="img">The new image.</param>
         public void DisplayInLeftPictureBox(Image img)
         {
             pictureBoxLeft.Image = img;
             pictureBoxLeft.Refresh();
         }
 
+        /// <summary>
+        /// Displays an image in the right Picture box.
+        /// </summary>
+        /// <param name="img">The new image.</param>
         public void DisplayInRightPictureBox(Image img)
         {
             pictureBoxRight.Image = img;
@@ -556,345 +375,14 @@ namespace SketchAssistant
             MessageBox.Show(message);
         }
 
-        public bool ShowWarning(String message)
-        {
-            return (MessageBox.Show(message, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes);
-        }
-
-        /***********************************/
-        /*** HELPER FUNCTIONS START HERE ***/
-        /***********************************/
-
-        /// <summary>
-        /// A function that returns a white canvas for a given width and height.
-        /// </summary>
-        /// <param name="width">The width of the canvas in pixels</param>
-        /// <param name="height">The height of the canvas in pixels</param>
-        /// <returns>The new canvas</returns>
-        private Image GetEmptyCanvas(int width, int height)
-        {
-            Image image;
-            try
-            {
-                image = new Bitmap(width, height);
-            }
-            catch(ArgumentException e)
-            {
-                ShowInfoMessage("The requested canvas size caused an error: \n" + e.ToString() + "\n The Canvas will be set to match your window.");
-                image = new Bitmap(pictureBoxLeft.Width, pictureBoxLeft.Height);
-            }
-            Graphics graph = Graphics.FromImage(image);
-            graph.FillRectangle(Brushes.White, 0, 0, width + 10, height + 10);
-            return image;
-        }
-
-        /// <summary>
-        /// Creates an empty Canvas
-        /// </summary>
-        private void DrawEmptyCanvasRight()
-        {
-            if (leftImage == null)
-            {
-                SetAndRefreshRightImage(GetEmptyCanvas(pictureBoxRight.Width, pictureBoxRight.Height));
-            }
-            else
-            {
-                SetAndRefreshRightImage(GetEmptyCanvas(leftImage.Width, leftImage.Height));
-            }
-        }
-
-        /// <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)
-            {
-                SetAndRefreshLeftImage(GetEmptyCanvas(pictureBoxLeft.Width, pictureBoxLeft.Height));
-            }
-            else
-            {
-                SetAndRefreshLeftImage(GetEmptyCanvas(width, height));
-            }
-        }
-
-        /// <summary>
-        /// Redraws all lines in lineList, for which their associated boolean value equals true.
-        /// </summary>
-        private void RedrawRightImage()
-        {
-            var workingCanvas = GetEmptyCanvas(rightImage.Width, rightImage.Height);
-            var workingGraph = Graphics.FromImage(workingCanvas);
-            //Lines
-            foreach (Tuple<bool, Line> lineBoolTuple in rightLineList)
-            {
-                if (lineBoolTuple.Item1)
-                {
-                    lineBoolTuple.Item2.DrawLine(workingGraph);
-                }
-            }
-            //The Line being currently drawn
-            if(currentLine != null && currentLine.Count > 0 && currentState.Equals(ProgramState.Draw) && mousePressed)
-            {
-                var currLine = new Line(currentLine);
-                currLine.DrawLine(workingGraph);
-            }
-            //Overlay Items
-            foreach (HashSet<Point> item in overlayItems)
-            {
-                foreach(Point p in item)
-                {
-                    workingGraph.FillRectangle(Brushes.Green, p.X, p.Y, 1, 1);
-                }
-            }
-            SetAndRefreshRightImage(workingCanvas);
-        }
-
-        /// <summary>
-        /// A function to set rightImage and to refresh the respective PictureBox with it.
-        /// </summary>
-        /// <param name="image">The new Image</param>
-        private void SetAndRefreshRightImage(Image image)
-        {
-            rightImage = image;
-            pictureBoxRight.Image = rightImage;
-            pictureBoxRight.Refresh();
-        }
-
-        /// <summary>
-        /// A function to set leftImage and to refresh the respective PictureBox with it.
-        /// </summary>
-        /// <param name="image">The new Image</param>
-        private void SetAndRefreshLeftImage(Image image)
-        {
-            leftImage = image;
-            pictureBoxLeft.Image = leftImage;
-            pictureBoxLeft.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>
-        /// A helper function which handles tasks associated witch changing states, 
-        /// such as checking and unchecking buttons and changing the state.
-        /// </summary>
-        /// <param name="newState">The new state of the program</param>
-        private void ChangeState(ProgramState newState)
-        {
-            switch (currentState)
-            {
-                case ProgramState.Draw:
-                    drawButton.CheckState = CheckState.Unchecked;
-                    mouseTimer.Enabled = false;
-                    break;
-                case ProgramState.Delete:
-                    deleteButton.CheckState = CheckState.Unchecked;
-                    mouseTimer.Enabled = false;
-                    break;
-                default:
-                    break;
-            }
-            switch (newState)
-            {
-                case ProgramState.Draw:
-                    drawButton.CheckState = CheckState.Checked;
-                    mouseTimer.Enabled = true;
-                    break;
-                case ProgramState.Delete:
-                    deleteButton.CheckState = CheckState.Checked;
-                    mouseTimer.Enabled = true;
-                    break;
-                default:
-                    break;
-            }
-            currentState = newState;
-            pictureBoxRight.Refresh();
-        }
-
-        /// <summary>
-        /// A function that calculates the coordinates of a point on a zoomed in image.
-        /// </summary>
-        /// <param name="">The position of the mouse cursor</param>
-        /// <returns>The real coordinates of the mouse cursor on the image</returns>
-        private Point ConvertCoordinates(Point cursorPosition)
-        {
-            Point realCoordinates = new Point(5,3);
-            if(pictureBoxRight.Image == null)
-            {
-                return cursorPosition;
-            }
-
-            int widthImage = pictureBoxRight.Image.Width;
-            int heightImage = pictureBoxRight.Image.Height;
-            int widthBox = pictureBoxRight.Width;
-            int heightBox = pictureBoxRight.Height;
-
-            float imageRatio = (float)widthImage / (float)heightImage;
-            float containerRatio = (float)widthBox / (float)heightBox;
-
-            if (imageRatio >= containerRatio)
-            {
-                //Image is wider than it is high
-                float zoomFactor = (float)widthImage / (float)widthBox;
-                float scaledHeight = heightImage / zoomFactor;
-                float filler = (heightBox - scaledHeight) / 2;
-                realCoordinates.X = (int)(cursorPosition.X * zoomFactor);
-                realCoordinates.Y = (int)((cursorPosition.Y - filler) * zoomFactor);
-            }
-            else
-            {
-                //Image is higher than it is wide
-                float zoomFactor = (float)heightImage / (float)heightBox;
-                float scaledWidth = widthImage / zoomFactor;
-                float filler = (widthBox - scaledWidth) / 2;
-                realCoordinates.X = (int)((cursorPosition.X - filler) * zoomFactor);
-                realCoordinates.Y = (int)(cursorPosition.Y * zoomFactor);
-            }
-            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, int range)
-        {
-            HashSet<int> returnSet = new HashSet<int>();
-
-            foreach(Point pnt in GeometryCalculator.FilledCircleAlgorithm(p, (int)range))
-            {
-                if(pnt.X >= 0 && pnt.Y >= 0 && pnt.X < rightImage.Width && pnt.Y < rightImage.Height)
-                {
-                    if (isFilledMatrix[pnt.X, pnt.Y])
-                    {
-                        returnSet.UnionWith(linesMatrix[pnt.X, pnt.Y]);
-                    }
-                }
-            }
-            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>
-        /// Will calculate the start and endpoints of the given line on the right canvas.
-        /// </summary>
-        /// <param name="line">The line.</param>
-        /// <param name="size">The size of the circle with which the endpoints of the line are marked.</param>
-        private Tuple<HashSet<Point>, HashSet<Point>> CalculateStartAndEnd(Line line, int size)
-        {
-            var circle0 = GeometryCalculator.FilledCircleAlgorithm(line.GetStartPoint(), size);
-            var circle1 = GeometryCalculator.FilledCircleAlgorithm(line.GetEndPoint(), size);
-            var currentLineEndings = new Tuple<HashSet<Point>, HashSet<Point>>(circle0, circle1);
-            return currentLineEndings;
-        }
-
-        /// <summary>
-        /// A helper Function that updates the markerRadius & deletionRadius, considering the size of the canvas.
-        /// </summary>
-        private void UpdateSizes()
-        {
-            if (rightImage != null)
-            {
-                int widthImage = pictureBoxRight.Image.Width;
-                int heightImage = pictureBoxRight.Image.Height;
-                int widthBox = pictureBoxRight.Width;
-                int heightBox = pictureBoxRight.Height;
-                
-                float imageRatio = (float)widthImage / (float)heightImage;
-                float containerRatio = (float)widthBox / (float)heightBox;
-                float zoomFactor = 0;
-                if (imageRatio >= containerRatio)
-                {
-                    //Image is wider than it is high
-                    zoomFactor = (float)widthImage / (float)widthBox;
-                }
-                else
-                {
-                    //Image is higher than it is wide
-                    zoomFactor = (float)heightImage / (float)heightBox;
-                }
-                markerRadius = (int)(10 * zoomFactor);
-                redrawAss.SetMarkerRadius(markerRadius);
-                deletionRadius = (int)(5 * zoomFactor);
-            }
-        }
-
         /// <summary>
-        /// Checks if there is unsaved progess, and warns the user. Returns True if it safe to continue.
+        /// Shows a warning box with the given message (Yes/No Buttons)and returns true if the user aknowledges it.
         /// </summary>
-        /// <returns>true if there is none, or the user wishes to continue without saving.
-        /// false if there is progress, and the user doesn't wish to continue.</returns>
-        private bool CheckSavedStatus()
+        /// <param name="message">The message of the warning.</param>
+        /// <returns>True if the user confirms (Yes), negative if he doesn't (No)</returns>
+        public bool ShowWarning(String message)
         {
-            if (!historyOfActions.IsEmpty())
-            {
-                return (MessageBox.Show("You have unsaved changes, do you wish to continue?",
-                    "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes);
-            }
-            return true;
+            return (MessageBox.Show(message, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes);
         }
 
         /********************************************/
@@ -921,7 +409,7 @@ namespace SketchAssistant
             }
             return varArr;
         }
-
+        /*
         /// <summary>
         /// public method wrapper for testing purposes, invoking DrawEmptyCanvas(...) and BindAndDrawLeftImage(...)
         /// </summary>
@@ -933,5 +421,6 @@ namespace SketchAssistant
             DrawEmptyCanvasLeft(width, height);
             BindAndDrawLeftImage(newImage);
         }
+        */
     }
 }

+ 2 - 0
SketchAssistant/SketchAssistant/MVP_Model.cs

@@ -364,6 +364,8 @@ namespace SketchAssistant
             var workingCanvas = GetEmptyCanvas(width,height);
             var workingGraph = Graphics.FromImage(workingCanvas);
             leftLineList = listOfLines;
+            redrawAss = new RedrawAssistant(leftLineList);
+            overlayItems = redrawAss.Initialize(markerRadius);
             //Lines
             foreach (Line line in leftLineList)
             {

+ 2 - 2
SketchAssistant/SketchAssistant/MVP_Presenter.cs

@@ -13,7 +13,7 @@ namespace SketchAssistant
         /// <summary>
         /// The View of the MVP-Model, in this case Form1.
         /// </summary>
-        Form1 programView;
+        MVP_View programView;
         /// <summary>
         /// The Model of the MVP-Model.
         /// </summary>
@@ -41,7 +41,7 @@ namespace SketchAssistant
         private FileImporter fileImporter;
 
 
-        public MVP_Presenter(Form1 form)
+        public MVP_Presenter(MVP_View form)
         {
             programView = form;
             programModel = new MVP_Model(this);

+ 71 - 0
SketchAssistant/SketchAssistant/MVP_View.cs

@@ -0,0 +1,71 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Drawing;
+
+
+namespace SketchAssistant
+{
+    public interface MVP_View
+    {
+
+        /// <summary>
+        /// Enables the timer of the View, which will tick the Presenter.
+        /// </summary>
+        void EnableTimer();
+
+        /// <summary>
+        /// A function that opens a file dialog and returns the filename.
+        /// </summary>
+        /// <param name="Filter">The filter that should be applied to the new Dialog.</param>
+        /// <returns>Returns the FileName and the SafeFileName if the user correctly selects a file, 
+        /// else returns a tuple with empty strigns</returns>
+        Tuple<String, String> openNewDialog(String Filter);
+
+        /// <summary>
+        /// Sets the contents of the load status indicator label.
+        /// </summary>
+        /// <param name="message">The new contents</param>
+        void SetToolStripLoadStatus(String message);
+
+        /// <summary>
+        /// Sets the contents of the last action taken indicator label.
+        /// </summary>
+        /// <param name="message">The new contents</param>
+        void SetLastActionTakenText(String message);
+
+        /// <summary>
+        /// Changes the states of a tool strip button.
+        /// </summary>
+        /// <param name="buttonName">The name of the button.</param>
+        /// <param name="state">The new state of the button.</param>
+        void SetToolStripButtonStatus(String buttonName, Form1.ButtonState state);
+
+        /// <summary>
+        /// Displays an image in the left Picture box.
+        /// </summary>
+        /// <param name="img">The new image.</param>
+        void DisplayInLeftPictureBox(Image img);
+
+        /// <summary>
+        /// Displays an image in the right Picture box.
+        /// </summary>
+        /// <param name="img">The new image.</param>
+        void DisplayInRightPictureBox(Image img);
+
+        /// <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>
+        void ShowInfoMessage(String message);
+
+        /// <summary>
+        /// Shows a warning box with the given message (Yes/No Buttons)and returns true if the user aknowledges it.
+        /// </summary>
+        /// <param name="message">The message of the warning.</param>
+        /// <returns>True if the user confirms (Yes), negative if he doesn't (No)</returns>
+        bool ShowWarning(String message);
+    }
+}

+ 36 - 6
SketchAssistant/SketchAssistant/RedrawAssistant.cs

@@ -72,6 +72,27 @@ namespace SketchAssistant
             SetMarkerRadius(5);
         }
 
+        /// <summary>
+        /// Initialization function that returns the initial list of overlay points.
+        /// </summary>
+        /// <param name="mRad">The radius of the points.</param>
+        /// <returns>The list of overlay points.</returns>
+        public List<Tuple<bool, HashSet<Point>>> Initialize(int mRad)
+        {
+            if (isActive)
+            {
+                List<Tuple<bool, HashSet<Point>>> retList = new List<Tuple<bool, HashSet<Point>>>();
+                SetMarkerRadius(mRad);
+                foreach(Tuple<HashSet<Point>, HashSet<Point>> tup in startAndEndPoints)
+                {
+                    retList.Add(new Tuple<bool, HashSet<Point>>(false, tup.Item1));
+                    retList.Add(new Tuple<bool, HashSet<Point>>(false, tup.Item2));
+                }
+                return retList;
+            }
+            return null;
+        }
+
         /// <summary>
         /// The main functionality of the RedrawAssistant, which updates the Assistant according to the inputs given.
         /// </summary>
@@ -79,15 +100,23 @@ namespace SketchAssistant
         /// <param name="rightLines">The lines on the right canvas</param>
         /// <param name="currLineID">The id of the line currently being drawn.</param>
         /// <param name="lineFinished">A boolean to indicate that the line is finished</param>
-        /// <returns>A List of HashSets of Points, which are markers for the user to redraw lines.</returns>
-        public List<HashSet<Point>> Tick(Point currentPoint, List<Tuple<bool, Line>> rightLines, int currLineID, bool lineFinished)
+        /// <param name="overlayItems">A list containing the overlay items and if they should be drawn.</param>
+        /// <returns>The updated List of overlay items, or the same list if no changes need to be done, 
+        /// along with a boolean indicating if something was changed</returns>
+        public Tuple<bool, List<Tuple<bool, HashSet<Point>>>> Tick(Point currentPoint, List<Tuple<bool, Line>> rightLines, int currLineID, bool lineFinished, 
+            List<Tuple<bool, HashSet<Point>>> overlayItems)
         {
-            List<HashSet<Point>> returnList = new List<HashSet<Point>>();
-            if (!isActive) { return returnList; }
+            if (!isActive) { return new Tuple<bool, List<Tuple<bool, HashSet<Point>>>>(false, overlayItems); }
+
+            if (!currentlyRedrawing)
+            {
+
+            }
+            /*
             Tuple<Line, bool, int> newLineTuple = null;
             var returnAllStartPoints = true;
             CheckForUndrawnLines(rightLines);
-
+            
             // Checking if a startpoint is intersected
             if (!currentlyRedrawing)
             {
@@ -159,8 +188,9 @@ namespace SketchAssistant
                     }
                 }
             }
-
             return returnList;
+            */
+            return new Tuple<bool, List<Tuple<bool, HashSet<Point>>>>(false, overlayItems);
         }
 
         /// <summary>

+ 1 - 0
SketchAssistant/SketchAssistant/SketchAssistant.csproj

@@ -69,6 +69,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="MVP_View.cs" />
     <Compile Include="MVP_Presenter.cs" />
     <Compile Include="MVP_Model.cs" />
     <Compile Include="RedrawAssistant.cs" />