| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 | 
							- /*=========================================================================
 
-   Library:   CTK
 
-   Copyright (c) Kitware Inc.
 
-   Licensed under the Apache License, Version 2.0 (the "License");
 
-   you may not use this file except in compliance with the License.
 
-   You may obtain a copy of the License at
 
-       http://www.apache.org/licenses/LICENSE-2.0.txt
 
-   Unless required by applicable law or agreed to in writing, software
 
-   distributed under the License is distributed on an "AS IS" BASIS,
 
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
-   See the License for the specific language governing permissions and
 
-   limitations under the License.
 
- =========================================================================*/
 
- // Qt includes
 
- #include <QThread>
 
- // CTK includes
 
- #include "ctkVTKErrorLogMessageHandler.h"
 
- #include "ctkUtils.h"
 
- // VTK includes
 
- #include <vtkObjectFactory.h>
 
- #include <vtkOutputWindow.h>
 
- namespace {
 
- // --------------------------------------------------------------------------
 
- // ctkVTKOutputWindow
 
- // --------------------------------------------------------------------------
 
- class ctkVTKOutputWindow : public vtkOutputWindow
 
- {
 
- public:
 
-   static ctkVTKOutputWindow *New();
 
-   vtkTypeMacro(ctkVTKOutputWindow,vtkOutputWindow);
 
-   void PrintSelf(ostream& os, vtkIndent indent);
 
-   ctkVTKOutputWindow():MessageHandler(0){}
 
-   ~ctkVTKOutputWindow(){}
 
-   virtual void DisplayText(const char*);
 
-   virtual void DisplayErrorText(const char*);
 
-   virtual void DisplayWarningText(const char*);
 
-   virtual void DisplayGenericWarningText(const char*);
 
-   virtual void DisplayDebugText(const char*);
 
-   ctkErrorLogAbstractMessageHandler * MessageHandler;
 
- };
 
- // --------------------------------------------------------------------------
 
- // ctkVTKOutputWindow methods
 
- // --------------------------------------------------------------------------
 
- vtkStandardNewMacro(ctkVTKOutputWindow);
 
- //----------------------------------------------------------------------------
 
- void ctkVTKOutputWindow::PrintSelf(ostream& os, vtkIndent indent)
 
- {
 
-   this->Superclass::PrintSelf(os,indent);
 
- }
 
- //----------------------------------------------------------------------------
 
- void ctkVTKOutputWindow::DisplayText(const char* text)
 
- {
 
-   Q_ASSERT(this->MessageHandler);
 
-   this->MessageHandler->handleMessage(
 
-         ctk::qtHandleToString(QThread::currentThreadId()),
 
-         ctkErrorLogLevel::Info,
 
-         this->MessageHandler->handlerPrettyName(), text);
 
- }
 
- //----------------------------------------------------------------------------
 
- void ctkVTKOutputWindow::DisplayErrorText(const char* text)
 
- {
 
-   Q_ASSERT(this->MessageHandler);
 
-   this->MessageHandler->handleMessage(
 
-         ctk::qtHandleToString(QThread::currentThreadId()),
 
-         ctkErrorLogLevel::Error,
 
-         this->MessageHandler->handlerPrettyName(), text);
 
- }
 
- //----------------------------------------------------------------------------
 
- void ctkVTKOutputWindow::DisplayWarningText(const char* text)
 
- {
 
-   Q_ASSERT(this->MessageHandler);
 
-   this->MessageHandler->handleMessage(
 
-         ctk::qtHandleToString(QThread::currentThreadId()),
 
-         ctkErrorLogLevel::Warning,
 
-         this->MessageHandler->handlerPrettyName(), text);
 
- }
 
- //----------------------------------------------------------------------------
 
- void ctkVTKOutputWindow::DisplayGenericWarningText(const char* text)
 
- {
 
-   this->DisplayWarningText(text);
 
- }
 
- //----------------------------------------------------------------------------
 
- void ctkVTKOutputWindow::DisplayDebugText(const char* text)
 
- {
 
-   Q_ASSERT(this->MessageHandler);
 
-   this->MessageHandler->handleMessage(
 
-         ctk::qtHandleToString(QThread::currentThreadId()),
 
-         ctkErrorLogLevel::Debug,
 
-         this->MessageHandler->handlerPrettyName(), text);
 
- }
 
- } // End of anonymous namespace
 
- // --------------------------------------------------------------------------
 
- // ctkVTKErrorLogMessageHandlerPrivate
 
- // --------------------------------------------------------------------------
 
- class ctkVTKErrorLogMessageHandlerPrivate
 
- {
 
-   Q_DECLARE_PUBLIC(ctkVTKErrorLogMessageHandler);
 
- protected:
 
-   ctkVTKErrorLogMessageHandler* const q_ptr;
 
- public:
 
-   ctkVTKErrorLogMessageHandlerPrivate(ctkVTKErrorLogMessageHandler& object);
 
-   ~ctkVTKErrorLogMessageHandlerPrivate();
 
-   vtkOutputWindow * SavedVTKOutputWindow;
 
-   ctkVTKOutputWindow * CTKVTKOutputWindow;
 
- };
 
- // --------------------------------------------------------------------------
 
- // ctkVTKErrorLogMessageHandlerPrivate methods
 
- // --------------------------------------------------------------------------
 
- ctkVTKErrorLogMessageHandlerPrivate::
 
- ctkVTKErrorLogMessageHandlerPrivate(ctkVTKErrorLogMessageHandler& object) : q_ptr(&object)
 
- {
 
-   Q_Q(ctkVTKErrorLogMessageHandler);
 
-   this->SavedVTKOutputWindow = 0;
 
-   this->CTKVTKOutputWindow = ctkVTKOutputWindow::New();
 
-   this->CTKVTKOutputWindow->MessageHandler = q;
 
- }
 
- // --------------------------------------------------------------------------
 
- ctkVTKErrorLogMessageHandlerPrivate::~ctkVTKErrorLogMessageHandlerPrivate()
 
- {
 
-   if (this->SavedVTKOutputWindow)
 
-     {
 
-     this->SavedVTKOutputWindow->Delete();
 
-     }
 
-   this->CTKVTKOutputWindow->Delete();
 
- }
 
- // --------------------------------------------------------------------------
 
- // ctkVTKErrorLogMessageHandler methods
 
- // --------------------------------------------------------------------------
 
- QString ctkVTKErrorLogMessageHandler::HandlerName = QLatin1String("VTK");
 
- //----------------------------------------------------------------------------
 
- ctkVTKErrorLogMessageHandler::ctkVTKErrorLogMessageHandler() :
 
-   Superclass(), d_ptr(new ctkVTKErrorLogMessageHandlerPrivate(*this))
 
- {
 
- }
 
- //----------------------------------------------------------------------------
 
- ctkVTKErrorLogMessageHandler::~ctkVTKErrorLogMessageHandler()
 
- {
 
- }
 
- //----------------------------------------------------------------------------
 
- QString ctkVTKErrorLogMessageHandler::handlerName()const
 
- {
 
-   return ctkVTKErrorLogMessageHandler::HandlerName;
 
- }
 
- //----------------------------------------------------------------------------
 
- void ctkVTKErrorLogMessageHandler::setEnabledInternal(bool value)
 
- {
 
-   Q_D(ctkVTKErrorLogMessageHandler);
 
-   if (value)
 
-     {
 
-     d->SavedVTKOutputWindow = vtkOutputWindow::GetInstance();
 
-     d->SavedVTKOutputWindow->Register(0);
 
-     vtkOutputWindow::SetInstance(d->CTKVTKOutputWindow);
 
-     }
 
-   else
 
-     {
 
-     Q_ASSERT(d->SavedVTKOutputWindow);
 
-     vtkOutputWindow::SetInstance(d->SavedVTKOutputWindow);
 
-     d->SavedVTKOutputWindow->Delete();
 
-     d->SavedVTKOutputWindow = 0;
 
-     }
 
- }
 
 
  |