MainWindow.xaml.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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, 10);
  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.ChangeOptiTrack(false);
  150. ProgramPresenter.ChangeState(true);
  151. RightCanvas.EditingMode = InkCanvasEditingMode.Ink;
  152. }
  153. /// <summary>
  154. /// Changes the state of the program to drawing with OptiTrack
  155. /// </summary>
  156. private void DrawWithOptiButton_Click(object sender, RoutedEventArgs e)
  157. {
  158. ProgramPresenter.ChangeOptiTrack(true);
  159. ProgramPresenter.ChangeState(true);
  160. RightCanvas.EditingMode = InkCanvasEditingMode.Ink;
  161. }
  162. /// <summary>
  163. /// Hold left mouse button to start drawing.
  164. /// </summary>
  165. private void RightCanvas_MouseDown(object sender, MouseButtonEventArgs e)
  166. {
  167. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Down, strokeCollection);
  168. }
  169. /// <summary>
  170. /// Lift left mouse button to stop drawing and add a new Line.
  171. /// </summary>
  172. private void RightCanvas_MouseUp(object sender, MouseButtonEventArgs e)
  173. {
  174. if (strokeCollection.Count == 0)
  175. {
  176. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up_Invalid, strokeCollection);
  177. }
  178. else
  179. {
  180. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up, strokeCollection);
  181. RightCanvas.Strokes.RemoveAt(0);
  182. strokeCollection.RemoveAt(0);
  183. }
  184. }
  185. /// <summary>
  186. /// Is called when a stylus is lifted, which has the same effect as releasing the mouse.
  187. /// Lifting the finger when using touch also toggles this, therfore this function is sufficient.
  188. /// </summary>
  189. private void RightCanvas_IsStylusCapturedChanged(object sender, DependencyPropertyChangedEventArgs e)
  190. {
  191. System.Diagnostics.Debug.WriteLine("Stylus Capture is now: {0}", RightCanvas.IsStylusCaptured);
  192. if (!RightCanvas.IsStylusCaptured)
  193. {
  194. if (strokeCollection.Count == 0)
  195. {
  196. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up_Invalid, strokeCollection);
  197. }
  198. else
  199. {
  200. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up, strokeCollection);
  201. RightCanvas.Strokes.RemoveAt(0);
  202. strokeCollection.RemoveAt(0);
  203. }
  204. }
  205. }
  206. /// <summary>
  207. /// Get current Mouse positon within the right picture box.
  208. /// </summary>
  209. private void RightCanvas_MouseMove(object sender, MouseEventArgs e)
  210. {
  211. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, e.GetPosition(RightCanvas));
  212. }
  213. /// <summary>
  214. /// Button to create a new Canvas. Will create an empty image
  215. /// which is the size of the left image, if there is one.
  216. /// If there is no image loaded the canvas will be the size of the right picture box
  217. /// </summary>
  218. private void CanvasButton_Click(object sender, RoutedEventArgs e)
  219. {
  220. ProgramPresenter.NewCanvas();
  221. RightCanvas.EditingMode = InkCanvasEditingMode.Ink;
  222. RightCanvas.Strokes.Clear();
  223. }
  224. /// <summary>
  225. /// Ticks the Presenter.
  226. /// </summary>
  227. private void dispatcherTimer_Tick(object sender, EventArgs e)
  228. {
  229. ProgramPresenter.Tick();
  230. }
  231. /// <summary>
  232. /// Import button for .svg file, will open an OpenFileDialog
  233. /// </summary>
  234. private void SVGMenuItem_Click(object sender, RoutedEventArgs e)
  235. {
  236. if (ProgramPresenter.SVGToolStripMenuItemClick())
  237. RightCanvas.EditingMode = InkCanvasEditingMode.Ink;
  238. }
  239. /*************************/
  240. /*** PRESENTER -> VIEW ***/
  241. /*************************/
  242. /// <summary>
  243. /// Returns the cursor position.
  244. /// </summary>
  245. /// <returns>The cursor Position</returns>
  246. public Point GetCursorPosition()
  247. {
  248. return Mouse.GetPosition(RightCanvas);
  249. }
  250. /// <summary>
  251. /// If the mouse is pressed or not.
  252. /// </summary>
  253. /// <returns>Whether or not the mouse is pressed.</returns>
  254. public bool IsMousePressed()
  255. {
  256. if (!debugRunning)
  257. {
  258. return (Mouse.LeftButton.Equals(MouseButtonState.Pressed) || Mouse.RightButton.Equals(MouseButtonState.Pressed));
  259. }
  260. else return true;
  261. }
  262. /// <summary>
  263. /// Remove the current line.
  264. /// </summary>
  265. public void RemoveCurrLine()
  266. {
  267. RightCanvas.Children.Remove(currentLine);
  268. }
  269. /// <summary>
  270. /// Display the current line.
  271. /// </summary>
  272. /// <param name="line">The current line to display</param>
  273. public void DisplayCurrLine(Polyline line)
  274. {
  275. if (RightCanvas.Children.Contains(currentLine))
  276. {
  277. RemoveCurrLine();
  278. }
  279. RightCanvas.Children.Add(line);
  280. currentLine = line;
  281. }
  282. /// <summary>
  283. /// Removes all Lines from the left canvas.
  284. /// </summary>
  285. public void RemoveAllLeftLines()
  286. {
  287. LeftCanvas.Children.Clear();
  288. }
  289. /// <summary>
  290. /// Removes all lines in the right canvas.
  291. /// </summary>
  292. public void RemoveAllRightLines()
  293. {
  294. RightCanvas.Children.Clear();
  295. }
  296. /// <summary>
  297. /// Adds another Line that will be displayed in the left display.
  298. /// </summary>
  299. /// <param name="newLine">The new Polyline to be added displayed.</param>
  300. public void AddNewLineLeft(Polyline newLine)
  301. {
  302. newLine.Stroke = Brushes.Black;
  303. newLine.StrokeThickness = 2;
  304. LeftCanvas.Children.Add(newLine);
  305. }
  306. /// <summary>
  307. /// Adds another Line that will be displayed in the right display.
  308. /// </summary>
  309. /// <param name="newLine">The new Polyline to be added displayed.</param>
  310. public void AddNewLineRight(Polyline newLine)
  311. {
  312. newLine.Stroke = Brushes.Black;
  313. newLine.StrokeThickness = 2;
  314. RightCanvas.Children.Add(newLine);
  315. }
  316. /// <summary>
  317. /// Adds a point to the right canvas
  318. /// </summary>
  319. /// <param name="newPoint">The point</param>
  320. public void AddNewPointRight(Ellipse newPoint, InternalLine line)
  321. {
  322. newPoint.Height = 3; newPoint.Width = 3;
  323. newPoint.Fill = Brushes.Black;
  324. RightCanvas.Children.Add(newPoint);
  325. newPoint.Margin = new Thickness(line.point.X - 1.5, line.point.Y - 1.5, 0, 0);
  326. }
  327. /// <summary>
  328. /// Adds a point to the left canvas
  329. /// </summary>
  330. /// <param name="newPoint">The point</param>
  331. public void AddNewPointLeft(Ellipse newPoint)
  332. {
  333. newPoint.Height = 3; newPoint.Width = 3;
  334. newPoint.Fill = Brushes.Black;
  335. LeftCanvas.Children.Add(newPoint);
  336. }
  337. /// <summary>
  338. /// Enables the timer of the View, which will tick the Presenter.
  339. /// </summary>
  340. public void EnableTimer()
  341. {
  342. dispatcherTimer.Start();
  343. }
  344. /// <summary>
  345. /// A function that opens a file dialog and returns the filename.
  346. /// </summary>
  347. /// <param name="Filter">The filter that should be applied to the new Dialog.</param>
  348. /// <returns>Returns the FileName and the SafeFileName if the user correctly selects a file,
  349. /// else returns a tuple with empty strigns</returns>
  350. public Tuple<string, string> openNewDialog(string Filter)
  351. {
  352. openFileDialog.Filter = Filter;
  353. if (openFileDialog.ShowDialog() == true)
  354. {
  355. return new Tuple<string, string>(openFileDialog.FileName, openFileDialog.SafeFileName);
  356. }
  357. else
  358. {
  359. return new Tuple<string, string>("", "");
  360. }
  361. }
  362. /// <summary>
  363. /// Sets the contents of the last action taken indicator label.
  364. /// </summary>
  365. /// <param name="message">The new contents</param>
  366. public void SetLastActionTakenText(string message)
  367. {
  368. LastActionBox.Text = message;
  369. }
  370. /// <summary>
  371. /// Sets the contents of the last action taken indicator label.
  372. /// </summary>
  373. /// <param name="message">The new contents</param>
  374. public void SetOptiTrackText(string message)
  375. {
  376. OptiTrackBox.Text = message;
  377. }
  378. /// Sets the contents of the status bar label containing
  379. /// the similarity score of the left and right image.
  380. /// </summary>
  381. /// <param name="message">The message to be set,
  382. /// will be set to the default value if left empty.</param>
  383. public void SetImageSimilarityText(string message)
  384. {
  385. if (message.Count() > 0) LineSimilarityBox.Text = message;
  386. else LineSimilarityBox.Text = "-";
  387. }
  388. /// <summary>
  389. /// Changes the states of a tool strip button.
  390. /// </summary>
  391. /// <param name="buttonName">The name of the button.</param>
  392. /// <param name="state">The new state of the button.</param>
  393. public void SetToolStripButtonStatus(string buttonName, MainWindow.ButtonState state)
  394. {
  395. ButtonBase buttonToChange;
  396. bool isToggleable = false;
  397. switch (buttonName)
  398. {
  399. case "canvasButton":
  400. buttonToChange = CanvasButton;
  401. break;
  402. case "drawButton":
  403. buttonToChange = DrawButton;
  404. isToggleable = true;
  405. break;
  406. case "deleteButton":
  407. buttonToChange = DeleteButton;
  408. isToggleable = true;
  409. break;
  410. case "undoButton":
  411. buttonToChange = UndoButton;
  412. break;
  413. case "redoButton":
  414. buttonToChange = RedoButton;
  415. break;
  416. case "drawWithOptiButton":
  417. buttonToChange = DrawWithOptiButton;
  418. isToggleable = true;
  419. break;
  420. default:
  421. Console.WriteLine("Invalid Button was given to SetToolStripButton. \nMaybe you forgot to add a case?");
  422. return;
  423. }
  424. if (isToggleable)
  425. {
  426. switch (state)
  427. {
  428. case ButtonState.Active:
  429. ((ToggleButton)buttonToChange).IsEnabled = true;
  430. ((ToggleButton)buttonToChange).IsChecked = true;
  431. ((ToggleButton)buttonToChange).Opacity = 1;
  432. ((ToggleButton)buttonToChange).Background = Brushes.SkyBlue;
  433. break;
  434. case ButtonState.Disabled:
  435. ((ToggleButton)buttonToChange).IsEnabled = false;
  436. ((ToggleButton)buttonToChange).IsChecked = false;
  437. ((ToggleButton)buttonToChange).Opacity = 0.5;
  438. ((ToggleButton)buttonToChange).Background = Brushes.LightGray;
  439. break;
  440. case ButtonState.Enabled:
  441. ((ToggleButton)buttonToChange).IsEnabled = true;
  442. ((ToggleButton)buttonToChange).IsChecked = false;
  443. ((ToggleButton)buttonToChange).Opacity = 1;
  444. ((ToggleButton)buttonToChange).Background = Brushes.LightGray;
  445. break;
  446. }
  447. }
  448. else
  449. {
  450. switch (state)
  451. {
  452. case ButtonState.Disabled:
  453. ((Button)buttonToChange).IsEnabled = false;
  454. ((Button)buttonToChange).Opacity = 0.5;
  455. break;
  456. default:
  457. ((Button)buttonToChange).IsEnabled = true;
  458. ((Button)buttonToChange).Opacity = 1;
  459. break;
  460. }
  461. }
  462. }
  463. /// <summary>
  464. /// Sets the contents of the load status indicator label.
  465. /// </summary>
  466. /// <param name="message">The new contents</param>
  467. public void SetToolStripLoadStatus(string message)
  468. {
  469. LoadStatusBox.Text = message;
  470. }
  471. /// <summary>
  472. /// shows the given info message in a popup and asks the user to aknowledge it
  473. /// </summary>
  474. /// <param name="message">the message to show</param>
  475. public void ShowInfoMessage(string message)
  476. {
  477. MessageBox.Show(message);
  478. }
  479. /// <summary>
  480. /// Shows a warning box with the given message (Yes/No Buttons)and returns true if the user aknowledges it.
  481. /// </summary>
  482. /// <param name="message">The message of the warning.</param>
  483. /// <returns>True if the user confirms (Yes), negative if he doesn't (No)</returns>
  484. public bool ShowWarning(string message)
  485. {
  486. MessageBoxResult result = MessageBox.Show(message, "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning);
  487. return (result.Equals(MessageBoxResult.Yes));
  488. }
  489. /// <summary>
  490. /// Updates the colour of a canvas.
  491. /// </summary>
  492. /// <param name="canvasName">The name of the canvas to be updated.</param>
  493. /// <param name="active">Whether or not the canvas is active.</param>
  494. public void SetCanvasState(string canvasName, bool active)
  495. {
  496. switch (canvasName)
  497. {
  498. case ("LeftCanvas"):
  499. if (active) LeftCanvas.Background = Brushes.White;
  500. else LeftCanvas.Background = Brushes.SlateGray;
  501. break;
  502. case ("RightCanvas"):
  503. if (active) RightCanvas.Background = Brushes.White;
  504. else RightCanvas.Background = Brushes.SlateGray;
  505. break;
  506. default:
  507. throw new InvalidOperationException("Unknown canvas name, Check that the canvas passed is either LeftCanvas or RightCanvas");
  508. }
  509. }
  510. /************************/
  511. /*** HELPING FUNCTION ***/
  512. /************************/
  513. /// <summary>
  514. /// A function that generates the overlay elements and sets all their values.
  515. /// </summary>
  516. private void SetupOverlay()
  517. {
  518. DropShadowEffect effect = new DropShadowEffect(); effect.ShadowDepth = 0;
  519. OverlayCanvas.Background = null;
  520. //Startpoint of a line to be redrawn
  521. Ellipse StartPointOverlay = new Ellipse();
  522. StartPointOverlay.Height = markerRadius * 2; StartPointOverlay.Width = markerRadius * 2;
  523. StartPointOverlay.Fill = Brushes.Green;
  524. StartPointOverlay.Effect = effect;
  525. OverlayDictionary.Add("startpoint", StartPointOverlay);
  526. //Endpoint of a line to be redrawn
  527. Ellipse EndPointOverlay = new Ellipse();
  528. EndPointOverlay.Height = markerRadius * 2; EndPointOverlay.Width = markerRadius * 2;
  529. EndPointOverlay.Fill = Brushes.Green;
  530. EndPointOverlay.Effect = effect;
  531. OverlayDictionary.Add("endpoint", EndPointOverlay);
  532. //Pointer of the optitrack system
  533. Ellipse OptitrackMarker = new Ellipse(); OptitrackMarker.Height = 5; OptitrackMarker.Width = 5;
  534. OptitrackMarker.Fill = Brushes.LightGray;
  535. OptitrackMarker.Effect = effect;
  536. OverlayDictionary.Add("optipoint", OptitrackMarker);
  537. //10 Dotted Lines for debugging (if more are needed simply extend the for-loop
  538. for (int x = 0; x < 10; x++)
  539. {
  540. Line dotLine = new Line();
  541. dotLine.Stroke = Brushes.Red;
  542. dotLine.StrokeDashArray = new DoubleCollection { 2 + x, 2 + x };
  543. dotLine.StrokeThickness = 1;
  544. OverlayDictionary.Add("dotLine" + x.ToString(), dotLine);
  545. }
  546. //Common features of all overlay items
  547. foreach (KeyValuePair<String, Shape> s in OverlayDictionary)
  548. {
  549. OverlayCanvas.Children.Add(s.Value);
  550. s.Value.Opacity = 0.00001;
  551. s.Value.IsHitTestVisible = false;
  552. }
  553. }
  554. /// <summary>
  555. /// Sends inputs to the presenter simulating drawing, used for testing and debugging.
  556. /// Takes 7000ms
  557. /// </summary>
  558. private void DebugOne_Click(object sender, RoutedEventArgs e)
  559. {
  560. Debug(1);
  561. }
  562. /// <summary>
  563. /// Sends inputs to the presenter simulating drawing, used for testing and debugging.
  564. /// Takes 24000ms
  565. /// </summary>
  566. private void DebugTwo_Click(object sender, RoutedEventArgs e)
  567. {
  568. Debug(2);
  569. }
  570. /// <summary>
  571. /// Sends inputs to the presenter simulating drawing, used for testing and debugging.
  572. /// Takes 4000ms
  573. /// </summary>
  574. private void DebugThree_Click(object sender, RoutedEventArgs e)
  575. {
  576. Debug(3);
  577. }
  578. /// <summary>
  579. /// Sends inputs to the presenter simulating drawing, used for testing and debugging.
  580. /// Takes
  581. /// </summary>
  582. private void DebugFour_Click(object sender, RoutedEventArgs e)
  583. {
  584. Debug(4);
  585. }
  586. /// <summary>
  587. /// A function which simulates canvas input for debugging.
  588. /// </summary>
  589. /// <param name="option"></param>
  590. private async void Debug(int option)
  591. {
  592. Point[] points;
  593. Point start = new Point(50, 50);
  594. switch (option)
  595. {
  596. case 1:
  597. points = debugDat.debugPoints1;
  598. break;
  599. case 2:
  600. points = debugDat.debugPoints2;
  601. break;
  602. case 3:
  603. points = debugDat.debugPoints3;
  604. break;
  605. case 4:
  606. points = debugDat.debugPoints4;
  607. start = new Point(284, 148);
  608. break;
  609. default:
  610. return;
  611. }
  612. dispatcherTimer.Stop();
  613. debugRunning = true;
  614. ProgramPresenter.Tick(); await Task.Delay(10);
  615. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, start);
  616. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Down, strokeCollection); await Task.Delay(10);
  617. for (int x = 0; x < points.Length; x++)
  618. {
  619. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, points[x]);
  620. await Task.Delay(1);
  621. if (x % 5 == 0)
  622. {
  623. ProgramPresenter.Tick();
  624. await Task.Delay(1);
  625. }
  626. }
  627. ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up, strokeCollection); await Task.Delay(1);
  628. debugRunning = false;
  629. dispatcherTimer.Start();
  630. }
  631. }
  632. }