ctkITKErrorLogMessageHandler.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. // CTK includes
  15. #include "ctkITKErrorLogMessageHandler.h"
  16. #ifdef __GNUC__
  17. // Disable warnings related to 'itkSmartPointer.h' file
  18. // See http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html
  19. // Note: Ideally the incriminated functions and macros should be fixed upstream ...
  20. # pragma GCC diagnostic ignored "-Wold-style-cast"
  21. #endif
  22. // ITK includes
  23. #include <itkObjectFactory.h>
  24. #include <itkOutputWindow.h>
  25. namespace itk
  26. {
  27. // --------------------------------------------------------------------------
  28. // ctkITKOutputWindow
  29. // --------------------------------------------------------------------------
  30. class ctkITKOutputWindow : public OutputWindow
  31. {
  32. public:
  33. /** Standard class typedefs. */
  34. typedef ctkITKOutputWindow Self;
  35. typedef OutputWindow Superclass;
  36. typedef SmartPointer<Self> Pointer;
  37. typedef SmartPointer<const Self> ConstPointer;
  38. /** Standard New method. */
  39. itkNewMacro(ctkITKOutputWindow);
  40. /** Run-time type information (and related methods). */
  41. itkTypeMacro(ctkITKOutputWindow, OutputWindow);
  42. ctkITKOutputWindow():MessageHandler(0){}
  43. ~ctkITKOutputWindow(){}
  44. virtual void DisplayText(const char*);
  45. virtual void DisplayErrorText(const char*);
  46. virtual void DisplayWarningText(const char*);
  47. virtual void DisplayGenericWarningText(const char*);
  48. virtual void DisplayDebugText(const char*);
  49. ctkErrorLogAbstractMessageHandler * MessageHandler;
  50. };
  51. // --------------------------------------------------------------------------
  52. // ctkITKOutputWindow methods
  53. //----------------------------------------------------------------------------
  54. void ctkITKOutputWindow::DisplayText(const char* text)
  55. {
  56. this->MessageHandler->errorLogModel()->addEntry(
  57. ctkErrorLogModel::Info, this->MessageHandler->handlerPrettyName(), text);
  58. }
  59. //----------------------------------------------------------------------------
  60. void ctkITKOutputWindow::DisplayErrorText(const char* text)
  61. {
  62. this->MessageHandler->errorLogModel()->addEntry(
  63. ctkErrorLogModel::Error, this->MessageHandler->handlerPrettyName(), text);
  64. }
  65. //----------------------------------------------------------------------------
  66. void ctkITKOutputWindow::DisplayWarningText(const char* text)
  67. {
  68. this->MessageHandler->errorLogModel()->addEntry(
  69. ctkErrorLogModel::Warning, this->MessageHandler->handlerPrettyName(), text);
  70. }
  71. //----------------------------------------------------------------------------
  72. void ctkITKOutputWindow::DisplayGenericWarningText(const char* text)
  73. {
  74. this->DisplayWarningText(text);
  75. }
  76. //----------------------------------------------------------------------------
  77. void ctkITKOutputWindow::DisplayDebugText(const char* text)
  78. {
  79. this->MessageHandler->errorLogModel()->addEntry(
  80. ctkErrorLogModel::Debug, this->MessageHandler->handlerPrettyName(), text);
  81. }
  82. } // End of itk namespace
  83. // --------------------------------------------------------------------------
  84. // ctkITKErrorLogMessageHandlerPrivate
  85. // --------------------------------------------------------------------------
  86. class ctkITKErrorLogMessageHandlerPrivate
  87. {
  88. Q_DECLARE_PUBLIC(ctkITKErrorLogMessageHandler);
  89. protected:
  90. ctkITKErrorLogMessageHandler* const q_ptr;
  91. public:
  92. ctkITKErrorLogMessageHandlerPrivate(ctkITKErrorLogMessageHandler& object);
  93. ~ctkITKErrorLogMessageHandlerPrivate();
  94. itk::OutputWindow::Pointer SavedITKOutputWindow;
  95. itk::ctkITKOutputWindow::Pointer CTKITKOutputWindow;
  96. };
  97. // --------------------------------------------------------------------------
  98. // ctkITKErrorLogMessageHandlerPrivate methods
  99. // --------------------------------------------------------------------------
  100. ctkITKErrorLogMessageHandlerPrivate::
  101. ctkITKErrorLogMessageHandlerPrivate(ctkITKErrorLogMessageHandler& object) : q_ptr(&object)
  102. {
  103. Q_Q(ctkITKErrorLogMessageHandler);
  104. this->SavedITKOutputWindow = 0;
  105. this->CTKITKOutputWindow = itk::ctkITKOutputWindow::New();
  106. this->CTKITKOutputWindow->MessageHandler = q;
  107. }
  108. // --------------------------------------------------------------------------
  109. ctkITKErrorLogMessageHandlerPrivate::~ctkITKErrorLogMessageHandlerPrivate()
  110. {
  111. this->SavedITKOutputWindow = 0;
  112. this->CTKITKOutputWindow = 0;
  113. }
  114. // --------------------------------------------------------------------------
  115. // ctkITKErrorLogMessageHandler methods
  116. // --------------------------------------------------------------------------
  117. QString ctkITKErrorLogMessageHandler::HandlerName = QLatin1String("ITK");
  118. //----------------------------------------------------------------------------
  119. ctkITKErrorLogMessageHandler::ctkITKErrorLogMessageHandler() :
  120. Superclass(), d_ptr(new ctkITKErrorLogMessageHandlerPrivate(*this))
  121. {
  122. }
  123. //----------------------------------------------------------------------------
  124. ctkITKErrorLogMessageHandler::~ctkITKErrorLogMessageHandler()
  125. {
  126. }
  127. //----------------------------------------------------------------------------
  128. QString ctkITKErrorLogMessageHandler::handlerName()const
  129. {
  130. return ctkITKErrorLogMessageHandler::HandlerName;
  131. }
  132. //----------------------------------------------------------------------------
  133. void ctkITKErrorLogMessageHandler::setEnabledInternal(bool value)
  134. {
  135. Q_D(ctkITKErrorLogMessageHandler);
  136. if (value)
  137. {
  138. d->SavedITKOutputWindow = itk::OutputWindow::GetInstance();
  139. itk::OutputWindow::SetInstance(d->CTKITKOutputWindow);
  140. }
  141. else
  142. {
  143. Q_ASSERT(d->SavedITKOutputWindow.IsNotNull());
  144. itk::OutputWindow::SetInstance(d->SavedITKOutputWindow);
  145. d->SavedITKOutputWindow = 0;
  146. }
  147. }