MainWindow.xaml.cs 26 KB

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