MVP_Model.cs 25 KB

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