Device.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* This software is distributed under the Lesser General Public License */
  2. //
  3. // Device.cpp
  4. //
  5. // This file implements the classes GT_Device and GT_Device.
  6. //
  7. //------------------------------------------
  8. //
  9. // $Source: /home/br/CVS/graphlet/src/gt_base/Device.cpp,v $
  10. // $Author: himsolt $
  11. // $Revision: 1.2 $
  12. // $Date: 1999/03/05 20:43:23 $
  13. // $Locker: $
  14. // $State: Exp $
  15. //
  16. //------------------------------------------
  17. //
  18. // (C) University of Passau 1995-1999, graphlet Project
  19. //
  20. #include "Graphlet.h"
  21. #include "Device.h"
  22. // Appearant bug with MS Windows systems
  23. #ifdef WIN32
  24. #include "Common_Graphics.h"
  25. #include "UIObject.h"
  26. #endif
  27. //////////////////////////////////////////
  28. //
  29. // GT_Device
  30. //
  31. //////////////////////////////////////////
  32. GT_Device::GT_Device (const string& name,
  33. double scale_x,
  34. double scale_y) :
  35. the_objects (),
  36. the_name (name),
  37. the_scale_x (scale_x),
  38. the_scale_y (scale_y)
  39. {
  40. }
  41. GT_Device::~GT_Device ()
  42. {
  43. }
  44. void GT_Device::name (const string& n)
  45. {
  46. the_name = n;
  47. }
  48. void GT_Device::scale_x (double x)
  49. {
  50. the_scale_x = x;
  51. }
  52. void GT_Device::scale_y (double y)
  53. {
  54. the_scale_y = y;
  55. }
  56. void GT_Device::scale (double x, double y)
  57. {
  58. the_scale_x = x;
  59. the_scale_y = y;
  60. }
  61. GT_UIObject* GT_Device::insert (int uid, GT_UIObject* uiobject)
  62. {
  63. assert (uid >= 0);
  64. assert (uiobject != 0);
  65. the_objects[uid] = uiobject;
  66. return uiobject;
  67. }
  68. GT_UIObject* GT_Device::get (int id) const
  69. {
  70. if (the_objects.find(id) != the_objects.end()) {
  71. return (*the_objects.find(id)).second;
  72. } else {
  73. return 0;
  74. }
  75. }
  76. bool GT_Device::defined (int id) const
  77. {
  78. return the_objects.find(id) != the_objects.end();
  79. }
  80. bool GT_Device::del (int id)
  81. {
  82. the_objects.erase (id);
  83. return true;
  84. }
  85. bool GT_Device::del_full (int /* id */)
  86. {
  87. return false;
  88. }
  89. //
  90. // Coordinate transformation
  91. //
  92. double GT_Device::translate_x (double x) const
  93. {
  94. return x * the_scale_x;
  95. }
  96. double GT_Device::translate_y (double y) const
  97. {
  98. return y * the_scale_y;
  99. }
  100. double GT_Device::translate_x_reverse (double x) const
  101. {
  102. assert (the_scale_x != 0);
  103. return x / the_scale_x;
  104. }
  105. double GT_Device::translate_y_reverse (double y) const
  106. {
  107. assert (the_scale_y != 0);
  108. return y / the_scale_y;
  109. }
  110. //////////////////////////////////////////
  111. //
  112. // Translation Utilities
  113. //
  114. //////////////////////////////////////////
  115. void GT_Device::translate (double x[], double y[], int n) const
  116. {
  117. for (int i=0; i<n; i++) {
  118. x[i] = the_scale_x * x[i];
  119. y[i] = the_scale_y * y[i];
  120. }
  121. }
  122. void GT_Device::translate (double from_x[], double from_y[],
  123. double to_x[], double to_y[],
  124. int n) const
  125. {
  126. for (int i=0; i<n; i++) {
  127. to_x[i] = the_scale_x * from_x[i];
  128. to_y[i] = the_scale_y * from_y[i];
  129. }
  130. }