ctkVTKMagnifyWidgetTest1.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QApplication>
  16. #include <QTimer>
  17. // CTK includes
  18. #include "ctkVTKMagnifyWidget.h"
  19. // VTK includes
  20. #include <QVTKWidget.h>
  21. // STD includes
  22. #include <cstdlib>
  23. #include <iostream>
  24. //-----------------------------------------------------------------------------
  25. int ctkVTKMagnifyWidgetTest1(int argc, char * argv [] )
  26. {
  27. QApplication app(argc, argv);
  28. ctkVTKMagnifyWidget magnify;
  29. // check default values
  30. if (!magnify.showCursor() ||
  31. magnify.cursorPen().color() != magnify.palette().color(QPalette::Highlight) ||
  32. magnify.cursorPen().width() != 0 ||
  33. magnify.cursorPen().joinStyle() != Qt::MiterJoin ||
  34. magnify.cursorType() != ctkCursorPixmapWidget::CrossHairCursor ||
  35. magnify.marginColor() != magnify.palette().color(QPalette::Window) ||
  36. magnify.bullsEyeWidth() != 15 ||
  37. magnify.magnification() != 1.0 ||
  38. magnify.numberObserved() != 0)
  39. {
  40. std::cerr << "ctkVTKMagnifyWidget: Wrong default values. " << std::endl
  41. << " " << magnify.showCursor()
  42. << " " << qPrintable(magnify.cursorPen().color().name())
  43. << " " << magnify.cursorPen().width()
  44. << " " << static_cast<int>(magnify.cursorPen().joinStyle())
  45. << " " << magnify.cursorType()
  46. << " " << qPrintable(magnify.marginColor().name())
  47. << " " << magnify.bullsEyeWidth()
  48. << " " << magnify.magnification()
  49. << " " << magnify.numberObserved() << std::endl;
  50. return EXIT_FAILURE;
  51. }
  52. // Magnification
  53. magnify.setMagnification(10.5);
  54. if (magnify.magnification() != 10.5)
  55. {
  56. std::cerr << "ctkVTKMagnifyWidget:setMagnification failed. "
  57. << magnify.magnification() << std::endl;
  58. return EXIT_FAILURE;
  59. }
  60. // Adding / removing observed QVTKWidgets
  61. QList<QVTKWidget *> allVTKWidgets;
  62. int numVTKWidgets = 3;
  63. for (int i = 0; i < numVTKWidgets; i++)
  64. {
  65. allVTKWidgets.append(new QVTKWidget());
  66. }
  67. // Observe one widget
  68. magnify.observe(allVTKWidgets[0]);
  69. if (!magnify.isObserved(allVTKWidgets[0]) || magnify.isObserved(allVTKWidgets[1]) ||
  70. magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 1)
  71. {
  72. std::cerr << "ctkVTKMagnifyWidget:observe(QVTKWidget*) failed. "
  73. << "Number observed = " << magnify.numberObserved() << std::endl;
  74. return EXIT_FAILURE;
  75. }
  76. // Observe two more widgets
  77. magnify.observe(allVTKWidgets.mid(1,2));
  78. if (!magnify.isObserved(allVTKWidgets[0]) || !magnify.isObserved(allVTKWidgets[1]) ||
  79. !magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 3)
  80. {
  81. std::cerr << "ctkVTKMagnifyWidget:observe(QList<QVTKWidget*>) failed. "
  82. << "Number observed = " << magnify.numberObserved() << std::endl;
  83. return EXIT_FAILURE;
  84. }
  85. // Re-observe a widget
  86. magnify.observe(allVTKWidgets[2]);
  87. if (!magnify.isObserved(allVTKWidgets[0]) || !magnify.isObserved(allVTKWidgets[1]) ||
  88. !magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 3)
  89. {
  90. std::cerr << "ctkVTKMagnifyWidget:observe(QVTKWidget*) failed on re-observe. "
  91. << "Number observed = " << magnify.numberObserved() << std::endl;
  92. return EXIT_FAILURE;
  93. }
  94. // Re-observe a list of widgets
  95. magnify.observe(allVTKWidgets.mid(0,2));
  96. if (!magnify.isObserved(allVTKWidgets[0]) || !magnify.isObserved(allVTKWidgets[1]) ||
  97. !magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 3)
  98. {
  99. std::cerr << "ctkVTKMagnifyWidget:observe(QList<QVTKWidget*>) failed on re-observe. "
  100. << "Number observed = " << magnify.numberObserved() << std::endl;
  101. return EXIT_FAILURE;
  102. }
  103. // Remove a widget
  104. magnify.remove(allVTKWidgets[2]);
  105. if (!magnify.isObserved(allVTKWidgets[0]) || !magnify.isObserved(allVTKWidgets[1]) ||
  106. magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 2)
  107. {
  108. std::cerr << "ctkVTKMagnifyWidget:remove(QVTKWidget*) failed. "
  109. << "Number observed = " << magnify.numberObserved() << std::endl;
  110. return EXIT_FAILURE;
  111. }
  112. // Re-remove a widget
  113. magnify.remove(allVTKWidgets[2]);
  114. if (!magnify.isObserved(allVTKWidgets[0]) || !magnify.isObserved(allVTKWidgets[1]) ||
  115. magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 2)
  116. {
  117. std::cerr << "ctkVTKMagnifyWidget:remove(QVTKWidget*) failed on re-remove. "
  118. << "Number observed = " << magnify.numberObserved() << std::endl;
  119. return EXIT_FAILURE;
  120. }
  121. // Remove a list of widgets
  122. magnify.remove(allVTKWidgets.mid(0,2));
  123. if (magnify.isObserved(allVTKWidgets[0]) || magnify.isObserved(allVTKWidgets[1]) ||
  124. magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 0)
  125. {
  126. std::cerr << "ctkVTKMagnifyWidget:remove(QList<QVTKWidget*>) failed. "
  127. << "Number observed = " << magnify.numberObserved() << std::endl;
  128. return EXIT_FAILURE;
  129. }
  130. // Re-remove a list of widgets
  131. magnify.remove(allVTKWidgets.mid(1,2));
  132. if (magnify.isObserved(allVTKWidgets[0]) || magnify.isObserved(allVTKWidgets[1]) ||
  133. magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 0)
  134. {
  135. std::cerr << "ctkVTKMagnifyWidget:remove(QList<QVTKWidget*>) failed on re-remove. "
  136. << "Number observed = " << magnify.numberObserved() << std::endl;
  137. return EXIT_FAILURE;
  138. }
  139. // Observe a list of widgets of length one
  140. magnify.observe(allVTKWidgets.mid(1,1));
  141. if (magnify.isObserved(allVTKWidgets[0]) || !magnify.isObserved(allVTKWidgets[1]) ||
  142. magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 1)
  143. {
  144. std::cerr << "ctkVTKMagnifyWidget:observe(QList<QVTKWidget*>) failed on lists of "
  145. << "length 1. Number observed = " << magnify.numberObserved() << std::endl;
  146. return EXIT_FAILURE;
  147. }
  148. magnify.show();
  149. if (argc < 2 || QString(argv[1]) != "-I" )
  150. {
  151. QTimer::singleShot(200, &app, SLOT(quit()));
  152. }
  153. return app.exec();
  154. }