MainWindow.xaml.cs 26 KB

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