MVP_Model.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Controls;
  8. using System.Windows.Media;
  9. using System.Windows.Media.Imaging;
  10. using OptiTrack;
  11. using System.Runtime.InteropServices;
  12. using System.IO;
  13. namespace SketchAssistantWPF
  14. {
  15. public class MVP_Model
  16. {
  17. /// <summary>
  18. /// The Presenter of the MVP-Model.
  19. /// </summary>
  20. MVP_Presenter programPresenter;
  21. /// <summary>
  22. /// History of Actions
  23. /// </summary>
  24. ActionHistory historyOfActions;
  25. OptiTrackConnector connector;
  26. /***********************/
  27. /*** CLASS VARIABLES ***/
  28. /***********************/
  29. /// <summary>
  30. /// If the program is in drawing mode.
  31. /// </summary>
  32. bool inDrawingMode;
  33. /// <summary>
  34. /// if the program is using OptiTrack
  35. /// </summary>
  36. public bool optiTrackInUse { get; private set; }
  37. /// <summary>
  38. /// Size of deletion area
  39. /// </summary>
  40. int deletionRadius = 5;
  41. /// <summary>
  42. /// Size of areas marking endpoints of lines in the redraw mode.
  43. /// </summary>
  44. int markerRadius = 10;
  45. /// <summary>
  46. /// The Position of the Cursor in the right picture box
  47. /// </summary>
  48. Point currentCursorPosition;
  49. /// <summary>
  50. /// The Previous Cursor Position in the right picture box
  51. /// </summary>
  52. Point previousCursorPosition;
  53. /// <summary>
  54. /// Queue for the cursorPositions
  55. /// </summary>
  56. Queue<Point> cursorPositions = new Queue<Point>();
  57. /// <summary>
  58. /// Lookup Matrix for checking postions of lines in the image
  59. /// </summary>
  60. bool[,] isFilledMatrix;
  61. /// <summary>
  62. /// Lookup Matrix for getting line ids at a certain postions of the image
  63. /// </summary>
  64. HashSet<int>[,] linesMatrix;
  65. /// <summary>
  66. /// List of items which will be overlayed over the right canvas.
  67. /// </summary>
  68. List<Tuple<bool, HashSet<Point>>> overlayItems;
  69. /// <summary>
  70. /// Width of the LeftImageBox.
  71. /// </summary>
  72. public int leftImageBoxWidth;
  73. /// <summary>
  74. /// Height of the LeftImageBox.
  75. /// </summary>
  76. public int leftImageBoxHeight;
  77. /// <summary>
  78. /// Width of the RightImageBox.
  79. /// </summary>
  80. public int rightImageBoxWidth;
  81. /// <summary>
  82. /// Height of the RightImageBox.
  83. /// </summary>
  84. public int rightImageBoxHeight;
  85. public ImageDimension leftImageSize { get; private set; }
  86. public ImageDimension rightImageSize { get; private set; }
  87. /// <summary>
  88. /// Indicates whether or not the canvas on the right side is active.
  89. /// </summary>
  90. public bool canvasActive { get; set; }
  91. /// <summary>
  92. /// Indicates if there is a graphic loaded in the left canvas.
  93. /// </summary>
  94. public bool graphicLoaded { get; set; }
  95. /// <summary>
  96. /// Whether or not an optitrack system is avaiable.
  97. /// </summary>
  98. public bool optitrackAvailable { get; private set; }
  99. /// <summary>
  100. /// x koordinate in real world. one unit is one meter. If standing in front of video wall facing it, moving left results in incrementation of x.
  101. /// </summary>
  102. public float optiTrackX;
  103. /// <summary>
  104. /// y koordinate in real world. one unit is one meter. If standing in front of video wall, moving up results in incrementation of y.
  105. /// </summary>
  106. public float optiTrackY;
  107. /// <summary>
  108. /// z koordinate in real world. one unit is one meter. If standing in front of video wall, moving back results in incrementation of y.
  109. /// </summary>
  110. public float optiTrackZ;
  111. /// <summary>
  112. /// keeps track of whether last tick the trackable was inside drawing zone or not.
  113. /// </summary>
  114. private bool optiTrackInsideDrawingZone = false;
  115. /// <summary>
  116. /// this is a variable used for detecting whether the tracker is in the warning zone (0 +- variable), no drawing zone (0 +- 2 * variable) or normal drawing zone
  117. /// </summary>
  118. private double WARNING_ZONE_BOUNDARY = 0.10; //10cm
  119. /// <summary>
  120. /// object of class Armband used for controlling the vibrotactil armband
  121. /// </summary>
  122. private Armband armband;
  123. /// <summary>
  124. /// deactivates all Console.WriteLine() when set to false
  125. /// </summary>
  126. bool testing = false;//TODO: remove after finishing userstory
  127. Image rightImageWithoutOverlay;
  128. /// <summary>
  129. /// Whether or not the mouse is pressed.
  130. /// </summary>
  131. private bool mouseDown;
  132. List<InternalLine> leftLineList;
  133. List<Tuple<bool, InternalLine>> rightLineList;
  134. List<Point> currentLine = new List<Point>();
  135. public MVP_Model(MVP_Presenter presenter)
  136. {
  137. programPresenter = presenter;
  138. historyOfActions = new ActionHistory();
  139. //redrawAss = new RedrawAssistant();
  140. //overlayItems = new List<Tuple<bool, HashSet<Point>>>();
  141. rightLineList = new List<Tuple<bool, InternalLine>>();
  142. canvasActive = false;
  143. UpdateUI();
  144. rightImageSize = new ImageDimension(0, 0);
  145. leftImageSize = new ImageDimension(0, 0);
  146. connector = new OptiTrackConnector();
  147. armband = new Armband();
  148. optitrackAvailable = false;
  149. if (File.Exists(@"C:\Users\videowall-pc-user\Documents\BP-SketchAssistant\SketchAssistant\optitrack_setup.ttp"))
  150. {
  151. if (connector.Init(@"C:\Users\videowall-pc-user\Documents\BP-SketchAssistant\SketchAssistant\optitrack_setup.ttp"))
  152. {
  153. optitrackAvailable = true;
  154. connector.StartTracking(getOptiTrackPosition);
  155. }
  156. }
  157. }
  158. [DllImport("user32.dll", EntryPoint = "SetCursorPos")]
  159. private static extern bool SetCursorPos(int X, int Y);
  160. //[DllImport("user32.dll")]
  161. //public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
  162. public enum MouseEventType : int
  163. {
  164. LeftDown = 0x02,
  165. LeftUp = 0x04,
  166. RightDown = 0x08,
  167. RightUp = 0x10
  168. }
  169. /**************************/
  170. /*** INTERNAL FUNCTIONS ***/
  171. /**************************/
  172. /// <summary>
  173. /// Change the status of whether or not the lines are shown.
  174. /// </summary>
  175. /// <param name="lines">The HashSet containing the affected Line IDs.</param>
  176. /// <param name="shown">True if the lines should be shown, false if they should be hidden.</param>
  177. private void ChangeLines(HashSet<int> lines, bool shown)
  178. {
  179. foreach (int lineId in lines)
  180. {
  181. if (lineId <= rightLineList.Count - 1 && lineId >= 0)
  182. {
  183. rightLineList[lineId] = new Tuple<bool, InternalLine>(shown, rightLineList[lineId].Item2);
  184. }
  185. }
  186. }
  187. /// <summary>
  188. /// A function that populates the matrixes needed for deletion detection with line data.
  189. /// </summary>
  190. private void RepopulateDeletionMatrixes()
  191. {
  192. if (canvasActive)
  193. {
  194. isFilledMatrix = new bool[rightImageSize.Width, rightImageSize.Height];
  195. linesMatrix = new HashSet<int>[rightImageSize.Width, rightImageSize.Height];
  196. foreach (Tuple<bool, InternalLine> lineTuple in rightLineList)
  197. {
  198. if (lineTuple.Item1)
  199. {
  200. lineTuple.Item2.PopulateMatrixes(isFilledMatrix, linesMatrix);
  201. }
  202. }
  203. }
  204. }
  205. /// <summary>
  206. /// Tells the Presenter to Update the UI
  207. /// </summary>
  208. private void UpdateUI()
  209. {
  210. programPresenter.UpdateUIState(inDrawingMode, historyOfActions.CanUndo(), historyOfActions.CanRedo(), canvasActive, graphicLoaded, optitrackAvailable, optiTrackInUse);
  211. }
  212. /// <summary>
  213. /// A function that checks the deletion matrixes at a certain point
  214. /// and returns all Line ids at that point and in a square around it in a certain range.
  215. /// </summary>
  216. /// <param name="p">The point around which to check.</param>
  217. /// <param name="range">The range around the point. If range is 0, only the point is checked.</param>
  218. /// <returns>A List of all lines.</returns>
  219. private HashSet<int> CheckDeletionMatrixesAroundPoint(Point p, int range)
  220. {
  221. HashSet<int> returnSet = new HashSet<int>();
  222. foreach (Point pnt in GeometryCalculator.FilledCircleAlgorithm(p, (int)range))
  223. {
  224. if (pnt.X >= 0 && pnt.Y >= 0 && pnt.X < rightImageSize.Width && pnt.Y < rightImageSize.Height)
  225. {
  226. if (isFilledMatrix[(int)pnt.X, (int)pnt.Y])
  227. {
  228. returnSet.UnionWith(linesMatrix[(int)pnt.X, (int)pnt.Y]);
  229. }
  230. }
  231. }
  232. return returnSet;
  233. }
  234. //TODO: calibrate
  235. double OPTITRACK_X_OFFSET = 0.7878;
  236. double OPTITRACK_Y_OFFSET = 0.7977;
  237. double OPTITRACK_CANVAS_HEIGHT = 1.29;
  238. double OPTITRACK_X_SCALE = -0.254 * (((1.816/*size of canvis*/ / 0.0254) * 96) / (1.816));
  239. double OPTITRACK_Y_SCALE = 0.254 * (((1.360 / 0.0254) * 96) / (1.360));
  240. /// <summary>
  241. /// converts given point to device-independent pixel
  242. /// </summary>
  243. /// <param name="p">real world coordinate</param>
  244. /// <returns>The given Point converted to device-independent pixel </returns>
  245. private Point ConvertTo96thsOfInch(Point p)
  246. {
  247. double xCoordinate = (p.X - OPTITRACK_X_OFFSET) * OPTITRACK_X_SCALE;
  248. double yCoordinate = (OPTITRACK_CANVAS_HEIGHT - (p.Y - OPTITRACK_Y_OFFSET)) * OPTITRACK_Y_SCALE;
  249. return new Point(xCoordinate, yCoordinate);
  250. }
  251. /// <summary>
  252. /// converts given point to pixel, calibrated for video wall in a08
  253. /// </summary>
  254. /// <param name="p"></param>
  255. /// <returns></returns>
  256. private Point ConvertToPixel(Point p)
  257. {//TODO: realize comments
  258. double xCoordinate = (p.X - OPTITRACK_X_OFFSET) * -1 * (/*Anzahl Pixel X-Richtung*/0 / (1.816)) + 0/*1/2 * x-richtung pixel*/; //TODO
  259. double yCoordinate = (((OPTITRACK_CANVAS_HEIGHT + 0/*meter von oberer Rand Leinwand zu oberer Rand Bildschirm*/) - (p.Y - OPTITRACK_Y_OFFSET))) * (/*Anzahl Pixel Y-Richtung*/0 / (1.360));
  260. return new Point(xCoordinate, yCoordinate);
  261. }
  262. /// <summary>
  263. /// Updates the current cursor position of the model.
  264. /// </summary>
  265. /// <param name="p">The new cursor position</param>
  266. public void SetCurrentFingerPosition(Point p)
  267. {
  268. Point correctedPoint = ConvertTo96thsOfInch(p);
  269. if (testing)
  270. {
  271. Console.WriteLine("raw coordinates: " + p.X + ";" + p.Y);
  272. Console.WriteLine(correctedPoint.X + "," + correctedPoint.Y);
  273. }
  274. currentCursorPosition = correctedPoint;
  275. }
  276. /********************************************/
  277. /*** FUNCTIONS TO INTERACT WITH PRESENTER ***/
  278. /********************************************/
  279. /// <summary>
  280. /// A function to update the dimensions of the left and right canvas when the window is resized.
  281. /// </summary>
  282. /// <param name="LeftCanvas">The size of the left canvas.</param>
  283. /// <param name="RightCanvas">The size of the right canvas.</param>
  284. public void ResizeEvent(ImageDimension LeftCanvas, ImageDimension RightCanvas)
  285. {
  286. if (LeftCanvas.Height >= 0 && LeftCanvas.Width >= 0) { leftImageSize = LeftCanvas; }
  287. if (RightCanvas.Height >= 0 && RightCanvas.Width >= 0) { rightImageSize = RightCanvas; }
  288. RepopulateDeletionMatrixes();
  289. }
  290. /// <summary>
  291. /// A function to reset the right image.
  292. /// </summary>
  293. public void ResetRightImage()
  294. {
  295. rightLineList.Clear();
  296. programPresenter.PassLastActionTaken(historyOfActions.Reset());
  297. programPresenter.ClearRightLines();
  298. }
  299. /// <summary>
  300. /// The function to set the left image.
  301. /// </summary>
  302. /// <param name="width">The width of the left image.</param>
  303. /// <param name="height">The height of the left image.</param>
  304. /// <param name="listOfLines">The List of Lines to be displayed in the left image.</param>
  305. public void SetLeftLineList(int width, int height, List<InternalLine> listOfLines)
  306. {
  307. leftImageSize = new ImageDimension(width, height);
  308. rightImageSize = new ImageDimension(width, height);
  309. leftLineList = listOfLines;
  310. graphicLoaded = true;
  311. programPresenter.UpdateLeftLines(leftLineList);
  312. CanvasActivated();
  313. /*
  314. var workingCanvas = GetEmptyCanvas(width, height);
  315. var workingGraph = Graphics.FromImage(workingCanvas);
  316. leftLineList = listOfLines;
  317. //redrawAss = new RedrawAssistant(leftLineList);
  318. //overlayItems = redrawAss.Initialize(markerRadius);
  319. //Lines
  320. foreach (InternalLine line in leftLineList)
  321. {
  322. line.DrawLine(workingGraph);
  323. }
  324. leftImage = workingCanvas;
  325. programPresenter.UpdateLeftImage(leftImage);
  326. //Set right image to same size as left image and delete linelist
  327. DrawEmptyCanvasRight();
  328. rightLineList = new List<Tuple<bool, InternalLine>>();
  329. */
  330. }
  331. /// <summary>
  332. /// A function to tell the model a new canvas was activated.
  333. /// </summary>
  334. public void CanvasActivated()
  335. {
  336. canvasActive = true;
  337. RepopulateDeletionMatrixes();
  338. UpdateUI();
  339. }
  340. /// <summary>
  341. /// Will undo the last action taken, if the action history allows it.
  342. /// </summary>
  343. public void Undo()
  344. {
  345. if (historyOfActions.CanUndo())
  346. {
  347. HashSet<int> affectedLines = historyOfActions.GetCurrentAction().GetLineIDs();
  348. SketchAction.ActionType undoAction = historyOfActions.GetCurrentAction().GetActionType();
  349. switch (undoAction)
  350. {
  351. case SketchAction.ActionType.Delete:
  352. //Deleted Lines need to be shown
  353. ChangeLines(affectedLines, true);
  354. break;
  355. case SketchAction.ActionType.Draw:
  356. //Drawn lines need to be hidden
  357. ChangeLines(affectedLines, false);
  358. break;
  359. default:
  360. break;
  361. }
  362. //TODO: For the person implementing overlay: Add check if overlay needs to be added
  363. programPresenter.UpdateRightLines(rightLineList);
  364. }
  365. RepopulateDeletionMatrixes();
  366. programPresenter.PassLastActionTaken(historyOfActions.MoveAction(true));
  367. UpdateUI();
  368. }
  369. /// <summary>
  370. /// Will redo the last action undone, if the action history allows it.
  371. /// </summary>
  372. public void Redo()
  373. {
  374. if (historyOfActions.CanRedo())
  375. {
  376. programPresenter.PassLastActionTaken(historyOfActions.MoveAction(false));
  377. HashSet<int> affectedLines = historyOfActions.GetCurrentAction().GetLineIDs();
  378. SketchAction.ActionType redoAction = historyOfActions.GetCurrentAction().GetActionType();
  379. switch (redoAction)
  380. {
  381. case SketchAction.ActionType.Delete:
  382. //Deleted Lines need to be redeleted
  383. ChangeLines(affectedLines, false);
  384. break;
  385. case SketchAction.ActionType.Draw:
  386. //Drawn lines need to be redrawn
  387. ChangeLines(affectedLines, true);
  388. break;
  389. default:
  390. break;
  391. }
  392. //TODO: For the person implementing overlay: Add check if overlay needs to be added
  393. programPresenter.UpdateRightLines(rightLineList);
  394. RepopulateDeletionMatrixes();
  395. }
  396. UpdateUI();
  397. }
  398. /// <summary>
  399. /// The function called by the Presenter to change the drawing state of the program.
  400. /// </summary>
  401. /// <param name="nowDrawing">The new drawingstate of the program</param>
  402. public void ChangeState(bool nowDrawing)
  403. {
  404. inDrawingMode = nowDrawing;
  405. UpdateUI();
  406. }
  407. /// <summary>
  408. /// The function called by the Presenter to set a variable which describes if OptiTrack is in use
  409. /// </summary>
  410. /// <param name="usingOptiTrack"></param>
  411. public void SetOptiTrack(bool usingOptiTrack)
  412. {
  413. optiTrackInUse = usingOptiTrack;
  414. if (usingOptiTrack && optiTrackX == 0 && optiTrackY == 0 && optiTrackZ == 0)
  415. {
  416. programPresenter.PassMessageToView("Trackable not detected, please check if OptiTrack is activated and Trackable is recognized", "Warning");
  417. }
  418. }
  419. /// <summary>
  420. /// Updates the current cursor position of the model.
  421. /// </summary>
  422. /// <param name="p">The new cursor position</param>
  423. public void SetCurrentCursorPosition(Point p)
  424. {
  425. if (!optiTrackInUse) currentCursorPosition = p;
  426. mouseDown = programPresenter.IsMousePressed();
  427. }
  428. /// <summary>
  429. /// Start a new Line, when the Mouse is pressed down.
  430. /// </summary>
  431. public void StartNewLine()
  432. {
  433. if (optiTrackInUse || programPresenter.IsMousePressed())
  434. {
  435. if (inDrawingMode)
  436. {
  437. currentLine.Clear();
  438. currentLine.Add(currentCursorPosition);
  439. }
  440. }
  441. }
  442. /// <summary>
  443. /// Finish the current Line, when the pressed Mouse is released.
  444. /// </summary>
  445. /// <param name="valid">Whether the up event is valid or not</param>
  446. public void FinishCurrentLine(bool valid)
  447. {
  448. foreach (Point p in currentLine)
  449. {
  450. if (testing)
  451. {
  452. Console.WriteLine(p.X + ";" + p.Y);
  453. }
  454. }
  455. if (valid)
  456. {
  457. if (inDrawingMode && currentLine.Count > 0)
  458. {
  459. InternalLine newLine = new InternalLine(currentLine, rightLineList.Count);
  460. rightLineList.Add(new Tuple<bool, InternalLine>(true, newLine));
  461. newLine.PopulateMatrixes(isFilledMatrix, linesMatrix);
  462. programPresenter.PassLastActionTaken(historyOfActions.AddNewAction(new SketchAction(SketchAction.ActionType.Draw, newLine.GetID())));
  463. //TODO: For the person implementing overlay: Add check if overlay needs to be added
  464. programPresenter.UpdateRightLines(rightLineList);
  465. currentLine.Clear();
  466. programPresenter.UpdateCurrentLine(currentLine);
  467. }
  468. }
  469. else
  470. {
  471. currentLine.Clear();
  472. }
  473. UpdateUI();
  474. }
  475. void getOptiTrackPosition(OptiTrack.Frame frame)
  476. {
  477. if(frame.Markers.Length > 1)
  478. {
  479. optiTrackX = frame.Markers[0].X;
  480. optiTrackY = frame.Markers[0].Y;
  481. optiTrackZ = frame.Markers[0].Z;
  482. }
  483. }
  484. /// <summary>
  485. /// Method to be called every tick. Updates the current Line, or checks for Lines to delete, depending on the drawing mode.
  486. /// </summary>
  487. public void Tick()
  488. {
  489. if (cursorPositions.Count > 0) { previousCursorPosition = cursorPositions.Dequeue(); }
  490. else { previousCursorPosition = currentCursorPosition; }
  491. if (optiTrackInUse) //drawing optiTrack
  492. {
  493. if (CheckInsideDrawingZone(optiTrackZ))
  494. {
  495. SetCurrentFingerPosition(new Point(optiTrackX, optiTrackY));
  496. currentLine.Add(currentCursorPosition);
  497. programPresenter.UpdateCurrentLine(currentLine);
  498. if (!optiTrackInsideDrawingZone)
  499. {
  500. optiTrackInsideDrawingZone = true;
  501. StartNewLine();
  502. if (testing)
  503. {
  504. Console.WriteLine("new line begun");
  505. }
  506. }
  507. if (optiTrackZ > WARNING_ZONE_BOUNDARY)
  508. {
  509. armband.pushForward();
  510. }
  511. else if (optiTrackZ < -1 * WARNING_ZONE_BOUNDARY)
  512. {
  513. armband.pushBackward();
  514. }
  515. }
  516. else
  517. {
  518. if (optiTrackInsideDrawingZone) //trackable was in drawing zone last tick -> finish line
  519. {
  520. optiTrackInsideDrawingZone = false;
  521. FinishCurrentLine(true);
  522. if (testing)
  523. {
  524. Console.WriteLine("line finished");
  525. }
  526. }
  527. }
  528. //if (optitrackAvailable) { TODO test and remove
  529. projectPointOntoScreen(optiTrackX, optiTrackY);
  530. //}
  531. cursorPositions.Enqueue(currentCursorPosition);
  532. }
  533. else //drawing normal
  534. {
  535. cursorPositions.Enqueue(currentCursorPosition);
  536. if (inDrawingMode && programPresenter.IsMousePressed())
  537. {
  538. currentLine.Add(currentCursorPosition);
  539. //programPresenter.UpdateCurrentLine(currentLine);
  540. }
  541. }
  542. //Deleting
  543. if (!inDrawingMode && programPresenter.IsMousePressed())
  544. {
  545. List<Point> uncheckedPoints = GeometryCalculator.BresenhamLineAlgorithm(previousCursorPosition, currentCursorPosition);
  546. foreach (Point currPoint in uncheckedPoints)
  547. {
  548. HashSet<int> linesToDelete = CheckDeletionMatrixesAroundPoint(currPoint, deletionRadius);
  549. if (linesToDelete.Count > 0)
  550. {
  551. programPresenter.PassLastActionTaken(historyOfActions.AddNewAction(new SketchAction(SketchAction.ActionType.Delete, linesToDelete)));
  552. foreach (int lineID in linesToDelete)
  553. {
  554. rightLineList[lineID] = new Tuple<bool, InternalLine>(false, rightLineList[lineID].Item2);
  555. }
  556. RepopulateDeletionMatrixes();
  557. //TODO: For the person implementing overlay: Add check if overlay needs to be added
  558. programPresenter.UpdateRightLines(rightLineList);
  559. }
  560. }
  561. }
  562. }
  563. private void projectPointOntoScreen(float optiTrackX, float optiTrackY)
  564. {
  565. Point auxiliaryPoint = ConvertToPixel(new Point(optiTrackX, optiTrackY));
  566. SetCursorPos((int)auxiliaryPoint.X, (int)auxiliaryPoint.Y);
  567. }
  568. private bool CheckInsideDrawingZone(float optiTrackZ)
  569. {
  570. if (Math.Abs(optiTrackZ) > WARNING_ZONE_BOUNDARY * 2) return false;
  571. return true;
  572. }
  573. /*
  574. /// <summary>
  575. /// A helper Function that updates the markerRadius & deletionRadius, considering the size of the canvas.
  576. /// </summary>
  577. /// <param name="CanvasSize">The size of the canvas</param>
  578. public void UpdateSizes(ImageDimension CanvasSize)
  579. {
  580. if (rightImageWithoutOverlay != null)
  581. {
  582. int widthImage = rightImageSize.Width;
  583. int heightImage = rightImageSize.Height;
  584. int widthBox = CanvasSize.Width;
  585. int heightBox = CanvasSize.Height;
  586. float imageRatio = (float)widthImage / (float)heightImage;
  587. float containerRatio = (float)widthBox / (float)heightBox;
  588. float zoomFactor = 0;
  589. if (imageRatio >= containerRatio)
  590. {
  591. //Image is wider than it is high
  592. zoomFactor = (float)widthImage / (float)widthBox;
  593. }
  594. else
  595. {
  596. //Image is higher than it is wide
  597. zoomFactor = (float)heightImage / (float)heightBox;
  598. }
  599. markerRadius = (int)(10 * zoomFactor);
  600. deletionRadius = (int)(5 * zoomFactor);
  601. }
  602. }
  603. */
  604. /// <summary>
  605. /// If there is unsaved progress.
  606. /// </summary>
  607. /// <returns>True if there is progress that has not been saved.</returns>
  608. public bool HasUnsavedProgress()
  609. {
  610. return !historyOfActions.IsEmpty();
  611. }
  612. }
  613. }