MainWindow.xaml.cs 25 KB

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