PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/ecg/third/wfdb-10.5.4/wave/grid.c

https://github.com/kastur/ECGCS
C | 125 lines | 74 code | 11 blank | 40 comment | 35 complexity | 6671de89105724373cebf03492df378d MD5 | raw file
  1. /* file: grid.c G. Moody 1 May 1990
  2. Last revised: 13 July 2010
  3. Grid drawing functions for WAVE
  4. -------------------------------------------------------------------------------
  5. WAVE: Waveform analyzer, viewer, and editor
  6. Copyright (C) 1990-2010 George B. Moody
  7. This program is free software; you can redistribute it and/or modify it under
  8. the terms of the GNU General Public License as published by the Free Software
  9. Foundation; either version 2 of the License, or (at your option) any later
  10. version.
  11. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  12. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  13. PARTICULAR PURPOSE. See the GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License along with
  15. this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  16. Place - Suite 330, Boston, MA 02111-1307, USA.
  17. You may contact the author by e-mail (george@mit.edu) or postal mail
  18. (MIT Room E25-505A, Cambridge, MA 02139 USA). For updates to this software,
  19. please visit PhysioNet (http://www.physionet.org/).
  20. _______________________________________________________________________________
  21. */
  22. #include "wave.h"
  23. #include "xvwave.h"
  24. static int grid_plotted;
  25. /* Call this function from the repaint procedure to restore the grid after
  26. the window has been cleared. */
  27. void restore_grid()
  28. {
  29. grid_plotted = 0;
  30. show_grid();
  31. }
  32. /* Show_grid() does what is necessary to display the grid in the requested
  33. style. Note that the grid can be made to disappear and reappear by show_grid()
  34. without redrawing it, by manipulating the color map. */
  35. void show_grid()
  36. {
  37. int i, ii, x, xx, y, yy;
  38. double dx, dxfine, dy, dyfine, vm;
  39. static int oghf, ogvf, grid_hidden;
  40. static double odx, ody;
  41. /* If the grid should not be visible, hide it if necessary. */
  42. if (!visible) {
  43. if (grid_plotted && !grid_hidden) {
  44. hide_grid();
  45. grid_hidden = 1;
  46. }
  47. return;
  48. }
  49. /* Calculate the grid spacing in pixels */
  50. if (tmag <= 0.0) tmag = 1.0;
  51. switch (gvflag) {
  52. case 0:
  53. case 1: dx = tmag * seconds(0.2); break;
  54. case 2: dx = tmag * seconds(0.2); dxfine = tmag * seconds(0.04); break;
  55. case 3: dx = tmag * seconds(300.0); dxfine = tmag * seconds(60.0); break;
  56. }
  57. if (vmag == NULL || vmag[0] == 0.0) vm = 1.0;
  58. else vm = vmag[0];
  59. switch (ghflag) {
  60. case 0:
  61. case 1: dy = vm * millivolts(0.5); break;
  62. case 2: dy = vm * millivolts(0.5);
  63. dyfine = vm * millivolts(0.1); break;
  64. }
  65. /* The grid must be drawn if it has not been plotted already, if the grid
  66. spacing or style has changed, or if we are not using a read/write color
  67. map. */
  68. if (!grid_plotted || ghflag != oghf || gvflag != ogvf ||
  69. (ghflag && dy != ody) || (gvflag && dx != odx) || !use_overlays) {
  70. XFillRectangle(display, osb, clear_grd,
  71. 0, 0, canvas_width,canvas_height);
  72. /* If horizontal grid lines are enabled, draw them. */
  73. if (ghflag)
  74. for (i = y = 0; y < canvas_height + dy; i++, y = i*dy) {
  75. if (0 < y && y < canvas_height)
  76. XDrawLine(display, osb,
  77. (ghflag > 1) ? draw_cgrd : draw_grd,
  78. 0, y, canvas_width, y);
  79. if (ghflag > 1) /* Draw fine horizontal grid lines. */
  80. for (ii = 1; ii < 5; ii++) {
  81. yy = y + ii*dyfine;
  82. XDrawLine(display, osb, draw_grd,
  83. 0, yy, canvas_width, yy);
  84. }
  85. }
  86. /* If vertical grid lines are enabled, draw them. */
  87. if (gvflag)
  88. for (i = x = 0; x < canvas_width + dx; i++, x = i*dx) {
  89. if (0 < x && x < canvas_width)
  90. XDrawLine(display, osb,
  91. (gvflag > 1) ? draw_cgrd : draw_grd,
  92. x, 0, x, canvas_height);
  93. if (gvflag > 1) /* Draw fine vertical grid lines. */
  94. for (ii = 1; ii < 5; ii++) {
  95. xx = x + ii*dxfine;
  96. XDrawLine(display, osb, draw_grd,
  97. xx, 0, xx, canvas_height);
  98. }
  99. }
  100. oghf = ghflag; ogvf = gvflag; odx = dx; ody = dy;
  101. grid_plotted = 1;
  102. }
  103. /* If the grid was hidden, make it visible by changing the color map. */
  104. if (grid_hidden) {
  105. unhide_grid();
  106. grid_hidden = 0;
  107. }
  108. }