MainWindow.xaml.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. using Microsoft.Win32;
  2. using OptiTrack;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Timers;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Controls.Primitives;
  14. using System.Windows.Data;
  15. using System.Windows.Documents;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. using System.Windows.Media.Imaging;
  19. using System.Windows.Navigation;
  20. using System.Windows.Shapes;
  21. using System.Windows.Threading;
  22. using System.Windows.Ink;
  23. using System.Windows.Media.Effects;
  24. namespace SketchAssistantWPF
  25. {
  26. /// <summary>
  27. /// Interaction logic for MainWindow.xaml
  28. /// </summary>
  29. public partial class MainWindow : Window, MVP_View
  30. {
  31. public MainWindow()
  32. {
  33. bool InDebugMode = false;
  34. String[] commArgs = Environment.GetCommandLineArgs();
  35. InitializeComponent();
  36. if (commArgs.Length > 1)
  37. {
  38. if (commArgs[1].Equals("-debug"))
  39. {
  40. InDebugMode = true;
  41. }
  42. }
  43. if (!InDebugMode)
  44. {
  45. DebugMode.Visibility = Visibility.Collapsed;
  46. }
  47. ProgramPresenter = new MVP_Presenter(this);
  48. // DispatcherTimer setup
  49. dispatcherTimer = new DispatcherTimer(DispatcherPriority.Render);
  50. dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
  51. dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 5);
  52. ProgramPresenter.Resize(new Tuple<int, int>((int)LeftCanvas.Width, (int)LeftCanvas.Height),
  53. new Tuple<int, int>((int)RightCanvas.Width, (int)RightCanvas.Height));
  54. //Setup overlay items
  55. SetupOverlay();
  56. }
  57. public enum ButtonState
  58. {
  59. Enabled,
  60. Disabled,
  61. Active
  62. }
  63. DispatcherTimer dispatcherTimer;
  64. /// <summary>
  65. /// Dialog to select a file.
  66. /// </summary>
  67. OpenFileDialog openFileDialog = new OpenFileDialog();
  68. /// <summary>
  69. /// All Lines in the current session
  70. /// </summary>
  71. List<Tuple<bool, InternalLine>> rightLineList = new List<Tuple<bool, InternalLine>>();
  72. /// <summary>
  73. /// Queue for the cursorPositions
  74. /// </summary>
  75. Queue<Point> cursorPositions = new Queue<Point>();
  76. /// <summary>
  77. /// The Presenter Component of the MVP-Model
  78. /// </summary>
  79. MVP_Presenter ProgramPresenter;
  80. /// <summary>
  81. /// The line currently being drawn
  82. /// </summary>
  83. Polyline currentLine;
  84. /// <summary>
  85. /// If the debug function is running.
  86. /// </summary>
  87. bool debugRunning = false;
  88. /// <summary>
  89. /// Point collections for debugging.
  90. /// </summary>
  91. DebugData debugDat = new DebugData();
  92. /// <summary>
  93. /// Stores Lines drawn on RightCanvas.
  94. /// </summary>
  95. public StrokeCollection strokeCollection = new StrokeCollection();
  96. /// <summary>
  97. /// Size of areas marking endpoints of lines in the redraw mode.
  98. /// </summary>
  99. public int markerRadius = 5;
  100. /// <summary>
  101. /// Dictionary containing the overlay elements
  102. /// </summary>
  103. public Dictionary<String, Shape> OverlayDictionary = new Dictionary<string, Shape>();
  104. /********************************************/
  105. /*** WINDOW SPECIFIC FUNCTIONS START HERE ***/
  106. /********************************************/
  107. /// <summary>
  108. /// Resize Function connected to the form resize event, will refresh the form when it is resized
  109. /// </summary>
  110. private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
  111. {
  112. ProgramPresenter.Resize(new Tuple<int, int>((int)LeftCanvas.ActualWidth, (int)LeftCanvas.ActualHeight),
  113. new Tuple<int, int>((int)RightCanvas.ActualWidth, (int)RightCanvas.ActualHeight));
  114. }
  115. /// <summary>
  116. /// Collects all Strokes on RightCanvas
  117. /// </summary>
  118. public void RightCanvas_StrokeCollection(object sender, InkCanvasStrokeCollectedEventArgs e)
  119. {
  120. strokeCollection.Add(e.Stroke);
  121. }
  122. /// <summary>
  123. /// Redo an Action.
  124. /// </summary>
  125. private void RedoButton_Click(object sender, RoutedEventArgs e)
  126. {
  127. if (!IsMousePressed()) ProgramPresenter.Redo();
  128. }
  129. /// <summary>
  130. /// Undo an Action.
  131. /// </summary>
  132. private void UndoButton_Click(object sender, RoutedEventArgs e)
  133. {
  134. if (!IsMousePressed()) ProgramPresenter.Undo();
  135. }
  136. /// <summary>
  137. /// Changes the state of the program to deletion
  138. /// </summary>
  139. private void DeleteButton_Click(object sender, RoutedEventArgs e)
  140. {
  141. ProgramPresenter.ChangeState(false);
  142. RightCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
  143. }
  144. /// <summary>
  145. /// Changes the state of the program to drawing
  146. /// </summary>
  147. private void DrawButton_Click(object sender, RoutedEventArgs e)
  148. {
  149. ProgramPresenter.ChangeState(true);
  150. RightCanvas.EditingMode = InkCanvasEditingMode.Ink;
  151. }
  152. /// <summary>
  153. /// Changes the state of the program to drawing with OptiTrack
  154. /// </summary>
  155. private void DrawWithOptiButton_Click(object sender, RoutedEventArgs e)
  156. {
  157. if (ProgramPresenter.GetOptitrackActive())
  158. {
  159. ProgramPresenter.ChangeOptiTrack(false);
  160. if (ProgramPresenter.GetDrawingState())
  161. RightCanvas.EditingMode = InkCanvasEditingMode.Ink;
  162. else
  163. RightCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
  164. }
  165. else
  166. {
  167. ProgramPresenter.ChangeOptiTrack(true);
  168. RightCanvas.EditingMode = InkCanvasEditingMode.None;
  169. }
  170. }
  171. /// <summary>
  172. /// Hold left mouse button to start drawing.
  173. /// </summary>
  174. private void RightCanvas_MouseDown(object sender, MouseButtonEventArgs e)
  175. {
  176. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Down, strokeCollection);
  177. }
  178. /// <summary>
  179. /// Lift left mouse button to stop drawing and add a new Line.
  180. /// </summary>
  181. private void RightCanvas_MouseUp(object sender, MouseButtonEventArgs e)
  182. {
  183. if (strokeCollection.Count == 0)
  184. {
  185. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up_Invalid, strokeCollection);
  186. }
  187. else
  188. {
  189. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up, strokeCollection);
  190. RightCanvas.Strokes.RemoveAt(0);
  191. strokeCollection.RemoveAt(0);
  192. }
  193. }
  194. /// <summary>
  195. /// Is called when a stylus is lifted, which has the same effect as releasing the mouse.
  196. /// Lifting the finger when using touch also toggles this, therfore this function is sufficient.
  197. /// </summary>
  198. private void RightCanvas_IsStylusCapturedChanged(object sender, DependencyPropertyChangedEventArgs e)
  199. {
  200. System.Diagnostics.Debug.WriteLine("Stylus Capture is now: {0}", RightCanvas.IsStylusCaptured);
  201. if (!RightCanvas.IsStylusCaptured)
  202. {
  203. if (strokeCollection.Count == 0)
  204. {
  205. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up_Invalid, strokeCollection);
  206. }
  207. else
  208. {
  209. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up, strokeCollection);
  210. RightCanvas.Strokes.RemoveAt(0);
  211. strokeCollection.RemoveAt(0);
  212. }
  213. }
  214. }
  215. /// <summary>
  216. /// Get current Mouse positon within the right picture box.
  217. /// </summary>
  218. private void RightCanvas_MouseMove(object sender, MouseEventArgs e)
  219. {
  220. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, e.GetPosition(RightCanvas));
  221. }
  222. /// <summary>
  223. /// Button to create a new Canvas. Will create an empty image
  224. /// which is the size of the left image, if there is one.
  225. /// If there is no image loaded the canvas will be the size of the right picture box
  226. /// </summary>
  227. private void CanvasButton_Click(object sender, RoutedEventArgs e)
  228. {
  229. ProgramPresenter.NewCanvas();
  230. RightCanvas.EditingMode = InkCanvasEditingMode.Ink;
  231. RightCanvas.Strokes.Clear();
  232. }
  233. /// <summary>
  234. /// Ticks the Presenter.
  235. /// </summary>
  236. private void dispatcherTimer_Tick(object sender, EventArgs e)
  237. {
  238. ProgramPresenter.Tick();
  239. }
  240. /// <summary>
  241. /// Import button for .svg file, will open an OpenFileDialog
  242. /// </summary>
  243. private void SVGMenuItem_Click(object sender, RoutedEventArgs e)
  244. {
  245. if (ProgramPresenter.SVGToolStripMenuItemClick())
  246. RightCanvas.EditingMode = InkCanvasEditingMode.Ink;
  247. }
  248. /*************************/
  249. /*** PRESENTER -> VIEW ***/
  250. /*************************/
  251. /// <summary>
  252. /// Returns the cursor position.
  253. /// </summary>
  254. /// <returns>The cursor Position</returns>
  255. public Point GetCursorPosition()
  256. {
  257. return Mouse.GetPosition(RightCanvas);
  258. }
  259. /// <summary>
  260. /// If the mouse is pressed or not.
  261. /// </summary>
  262. /// <returns>Whether or not the mouse is pressed.</returns>
  263. public bool IsMousePressed()
  264. {
  265. if (!debugRunning)
  266. {
  267. return (Mouse.LeftButton.Equals(MouseButtonState.Pressed) || Mouse.RightButton.Equals(MouseButtonState.Pressed));
  268. }
  269. else return true;
  270. }
  271. /// <summary>
  272. /// Remove the current line.
  273. /// </summary>
  274. public void RemoveCurrLine()
  275. {
  276. RightCanvas.Children.Remove(currentLine);
  277. }
  278. /// <summary>
  279. /// Display the current line.
  280. /// </summary>
  281. /// <param name="line">The current line to display</param>
  282. public void DisplayCurrLine(Polyline line)
  283. {
  284. if (RightCanvas.Children.Contains(currentLine))
  285. {
  286. RemoveCurrLine();
  287. }
  288. RightCanvas.Children.Add(line);
  289. currentLine = line;
  290. }
  291. /// <summary>
  292. /// Removes all Lines from the left canvas.
  293. /// </summary>
  294. public void RemoveAllLeftLines()
  295. {
  296. LeftCanvas.Children.Clear();
  297. }
  298. /// <summary>
  299. /// Removes all lines in the right canvas.
  300. /// </summary>
  301. public void RemoveAllRightLines()
  302. {
  303. RightCanvas.Children.Clear();
  304. }
  305. /// <summary>
  306. /// Adds another Line that will be displayed in the left display.
  307. /// </summary>
  308. /// <param name="newLine">The new Polyline to be added displayed.</param>
  309. public void AddNewLineLeft(Polyline newLine)
  310. {
  311. newLine.Stroke = Brushes.Black;
  312. newLine.StrokeThickness = 2;
  313. LeftCanvas.Children.Add(newLine);
  314. }
  315. /// <summary>
  316. /// Adds another Line that will be displayed in the right display.
  317. /// </summary>
  318. /// <param name="newLine">The new Polyline to be added displayed.</param>
  319. public void AddNewLineRight(Polyline newLine)
  320. {
  321. newLine.Stroke = Brushes.Black;
  322. newLine.StrokeThickness = 2;
  323. RightCanvas.Children.Add(newLine);
  324. }
  325. /// <summary>
  326. /// Adds a point to the right canvas
  327. /// </summary>
  328. /// <param name="newPoint">The point</param>
  329. public void AddNewPointRight(Ellipse newPoint, InternalLine line)
  330. {
  331. newPoint.Height = 3; newPoint.Width = 3;
  332. newPoint.Fill = Brushes.Black;
  333. RightCanvas.Children.Add(newPoint);
  334. newPoint.Margin = new Thickness(line.point.X - 1.5, line.point.Y - 1.5, 0, 0);
  335. }
  336. /// <summary>
  337. /// Adds a point to the left canvas
  338. /// </summary>
  339. /// <param name="newPoint">The point</param>
  340. public void AddNewPointLeft(Ellipse newPoint)
  341. {
  342. newPoint.Height = 3; newPoint.Width = 3;
  343. newPoint.Fill = Brushes.Black;
  344. LeftCanvas.Children.Add(newPoint);
  345. }
  346. /// <summary>
  347. /// Enables the timer of the View, which will tick the Presenter.
  348. /// </summary>
  349. public void EnableTimer()
  350. {
  351. dispatcherTimer.Start();
  352. }
  353. /// <summary>
  354. /// A function that opens a file dialog and returns the filename.
  355. /// </summary>
  356. /// <param name="Filter">The filter that should be applied to the new Dialog.</param>
  357. /// <returns>Returns the FileName and the SafeFileName if the user correctly selects a file,
  358. /// else returns a tuple with empty strigns</returns>
  359. public Tuple<string, string> openNewDialog(string Filter)
  360. {
  361. openFileDialog.Filter = Filter;
  362. if (openFileDialog.ShowDialog() == true)
  363. {
  364. return new Tuple<string, string>(openFileDialog.FileName, openFileDialog.SafeFileName);
  365. }
  366. else
  367. {
  368. return new Tuple<string, string>("", "");
  369. }
  370. }
  371. /// <summary>
  372. /// Sets the contents of the last action taken indicator label.
  373. /// </summary>
  374. /// <param name="message">The new contents</param>
  375. public void SetLastActionTakenText(string message)
  376. {
  377. LastActionBox.Text = message;
  378. }
  379. /// <summary>
  380. /// Sets the contents of the last action taken indicator label.
  381. /// </summary>
  382. /// <param name="message">The new contents</param>
  383. public void SetOptiTrackText(string message)
  384. {
  385. OptiTrackBox.Text = message;
  386. }
  387. /// Sets the contents of the status bar label containing
  388. /// the similarity score of the left and right image.
  389. /// </summary>
  390. /// <param name="message">The message to be set,
  391. /// will be set to the default value if left empty.</param>
  392. public void SetImageSimilarityText(string message)
  393. {
  394. if (message.Count() > 0) LineSimilarityBox.Text = message;
  395. else LineSimilarityBox.Text = "-";
  396. }
  397. /// <summary>
  398. /// Changes the states of a tool strip button.
  399. /// </summary>
  400. /// <param name="buttonName">The name of the button.</param>
  401. /// <param name="state">The new state of the button.</param>
  402. public void SetToolStripButtonStatus(string buttonName, MainWindow.ButtonState state)
  403. {
  404. ButtonBase buttonToChange;
  405. bool isToggleable = false;
  406. switch (buttonName)
  407. {
  408. case "canvasButton":
  409. buttonToChange = CanvasButton;
  410. break;
  411. case "drawButton":
  412. buttonToChange = DrawButton;
  413. isToggleable = true;
  414. break;
  415. case "deleteButton":
  416. buttonToChange = DeleteButton;
  417. isToggleable = true;
  418. break;
  419. case "undoButton":
  420. buttonToChange = UndoButton;
  421. break;
  422. case "redoButton":
  423. buttonToChange = RedoButton;
  424. break;
  425. case "drawWithOptiButton":
  426. buttonToChange = DrawWithOptiButton;
  427. isToggleable = true;
  428. break;
  429. default:
  430. Console.WriteLine("Invalid Button was given to SetToolStripButton. \nMaybe you forgot to add a case?");
  431. return;
  432. }
  433. if (isToggleable)
  434. {
  435. switch (state)
  436. {
  437. case ButtonState.Active:
  438. ((ToggleButton)buttonToChange).IsEnabled = true;
  439. ((ToggleButton)buttonToChange).IsChecked = true;
  440. ((ToggleButton)buttonToChange).Opacity = 1;
  441. ((ToggleButton)buttonToChange).Background = Brushes.SkyBlue;
  442. break;
  443. case ButtonState.Disabled:
  444. ((ToggleButton)buttonToChange).IsEnabled = false;
  445. ((ToggleButton)buttonToChange).IsChecked = false;
  446. ((ToggleButton)buttonToChange).Opacity = 0.5;
  447. ((ToggleButton)buttonToChange).Background = Brushes.LightGray;
  448. break;
  449. case ButtonState.Enabled:
  450. ((ToggleButton)buttonToChange).IsEnabled = true;
  451. ((ToggleButton)buttonToChange).IsChecked = false;
  452. ((ToggleButton)buttonToChange).Opacity = 1;
  453. ((ToggleButton)buttonToChange).Background = Brushes.LightGray;
  454. break;
  455. }
  456. }
  457. else
  458. {
  459. switch (state)
  460. {
  461. case ButtonState.Disabled:
  462. ((Button)buttonToChange).IsEnabled = false;
  463. ((Button)buttonToChange).Opacity = 0.5;
  464. break;
  465. default:
  466. ((Button)buttonToChange).IsEnabled = true;
  467. ((Button)buttonToChange).Opacity = 1;
  468. break;
  469. }
  470. }
  471. }
  472. /// <summary>
  473. /// Sets the contents of the load status indicator label.
  474. /// </summary>
  475. /// <param name="message">The new contents</param>
  476. public void SetToolStripLoadStatus(string message)
  477. {
  478. LoadStatusBox.Text = message;
  479. }
  480. /// <summary>
  481. /// shows the given info message in a popup and asks the user to aknowledge it
  482. /// </summary>
  483. /// <param name="message">the message to show</param>
  484. public void ShowInfoMessage(string message)
  485. {
  486. MessageBox.Show(message);
  487. }
  488. /// <summary>
  489. /// Shows a warning box with the given message (Yes/No Buttons)and returns true if the user aknowledges it.
  490. /// </summary>
  491. /// <param name="message">The message of the warning.</param>
  492. /// <returns>True if the user confirms (Yes), negative if he doesn't (No)</returns>
  493. public bool ShowWarning(string message)
  494. {
  495. MessageBoxResult result = MessageBox.Show(message, "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning);
  496. return (result.Equals(MessageBoxResult.Yes));
  497. }
  498. /// <summary>
  499. /// Updates the colour of a canvas.
  500. /// </summary>
  501. /// <param name="canvasName">The name of the canvas to be updated.</param>
  502. /// <param name="active">Whether or not the canvas is active.</param>
  503. public void SetCanvasState(string canvasName, bool active)
  504. {
  505. switch (canvasName)
  506. {
  507. case ("LeftCanvas"):
  508. if (active) LeftCanvas.Background = Brushes.White;
  509. else LeftCanvas.Background = Brushes.SlateGray;
  510. break;
  511. case ("RightCanvas"):
  512. if (active) RightCanvas.Background = Brushes.White;
  513. else RightCanvas.Background = Brushes.SlateGray;
  514. break;
  515. default:
  516. throw new InvalidOperationException("Unknown canvas name, Check that the canvas passed is either LeftCanvas or RightCanvas");
  517. }
  518. }
  519. /************************/
  520. /*** HELPING FUNCTION ***/
  521. /************************/
  522. /// <summary>
  523. /// A function that generates the overlay elements and sets all their values.
  524. /// </summary>
  525. private void SetupOverlay()
  526. {
  527. DropShadowEffect effect = new DropShadowEffect(); effect.ShadowDepth = 0;
  528. OverlayCanvas.Background = null;
  529. //Startpoint of a line to be redrawn
  530. Ellipse StartPointOverlay = new Ellipse();
  531. StartPointOverlay.Height = markerRadius * 2; StartPointOverlay.Width = markerRadius * 2;
  532. StartPointOverlay.Fill = Brushes.Green;
  533. StartPointOverlay.Effect = effect;
  534. OverlayDictionary.Add("startpoint", StartPointOverlay);
  535. //Endpoint of a line to be redrawn
  536. Ellipse EndPointOverlay = new Ellipse();
  537. EndPointOverlay.Height = markerRadius * 2; EndPointOverlay.Width = markerRadius * 2;
  538. EndPointOverlay.Fill = Brushes.Green;
  539. EndPointOverlay.Effect = effect;
  540. OverlayDictionary.Add("endpoint", EndPointOverlay);
  541. //Pointer of the optitrack system
  542. Ellipse OptitrackMarker = new Ellipse(); OptitrackMarker.Height = 5; OptitrackMarker.Width = 5;
  543. OptitrackMarker.Fill = Brushes.LightGray;
  544. OptitrackMarker.Effect = effect;
  545. OverlayDictionary.Add("optipoint", OptitrackMarker);
  546. //10 Dotted Lines for debugging (if more are needed simply extend the for-loop
  547. for (int x = 0; x < 10; x++)
  548. {
  549. Line dotLine = new Line();
  550. dotLine.Stroke = Brushes.Red;
  551. dotLine.StrokeDashArray = new DoubleCollection { 2 + x, 2 + x };
  552. dotLine.StrokeThickness = 1;
  553. OverlayDictionary.Add("dotLine" + x.ToString(), dotLine);
  554. }
  555. //Common features of all overlay items
  556. foreach (KeyValuePair<String, Shape> s in OverlayDictionary)
  557. {
  558. OverlayCanvas.Children.Add(s.Value);
  559. s.Value.Opacity = 0.00001;
  560. s.Value.IsHitTestVisible = false;
  561. }
  562. }
  563. /// <summary>
  564. /// Sends inputs to the presenter simulating drawing, used for testing and debugging.
  565. /// Takes 7000ms
  566. /// </summary>
  567. private void DebugOne_Click(object sender, RoutedEventArgs e)
  568. {
  569. Debug(1);
  570. }
  571. /// <summary>
  572. /// Sends inputs to the presenter simulating drawing, used for testing and debugging.
  573. /// Takes 24000ms
  574. /// </summary>
  575. private void DebugTwo_Click(object sender, RoutedEventArgs e)
  576. {
  577. Debug(2);
  578. }
  579. /// <summary>
  580. /// Sends inputs to the presenter simulating drawing, used for testing and debugging.
  581. /// Takes 4000ms
  582. /// </summary>
  583. private void DebugThree_Click(object sender, RoutedEventArgs e)
  584. {
  585. Debug(3);
  586. }
  587. /// <summary>
  588. /// Sends inputs to the presenter simulating drawing, used for testing and debugging.
  589. /// Takes
  590. /// </summary>
  591. private void DebugFour_Click(object sender, RoutedEventArgs e)
  592. {
  593. Debug(4);
  594. }
  595. /// <summary>
  596. /// A function which simulates canvas input for debugging.
  597. /// </summary>
  598. /// <param name="option"></param>
  599. private async void Debug(int option)
  600. {
  601. Point[] points;
  602. Point start = new Point(50, 50);
  603. switch (option)
  604. {
  605. case 1:
  606. points = debugDat.debugPoints1;
  607. break;
  608. case 2:
  609. points = debugDat.debugPoints2;
  610. break;
  611. case 3:
  612. points = debugDat.debugPoints3;
  613. break;
  614. case 4:
  615. points = debugDat.debugPoints4;
  616. start = new Point(284, 148);
  617. break;
  618. default:
  619. return;
  620. }
  621. dispatcherTimer.Stop();
  622. debugRunning = true;
  623. ProgramPresenter.Tick(); await Task.Delay(10);
  624. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, start);
  625. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Down, strokeCollection); await Task.Delay(10);
  626. for (int x = 0; x < points.Length; x++)
  627. {
  628. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, points[x]);
  629. await Task.Delay(1);
  630. if (x % 5 == 0)
  631. {
  632. ProgramPresenter.Tick();
  633. await Task.Delay(1);
  634. }
  635. }
  636. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up, strokeCollection); await Task.Delay(1);
  637. debugRunning = false;
  638. dispatcherTimer.Start();
  639. }
  640. }
  641. }