From 74842f999451bcd96b648a9d4c750bb6def5f825 Mon Sep 17 00:00:00 2001 From: san Date: Thu, 4 Dec 2008 15:27:25 +0000 Subject: [PATCH] Redirecting diagnostic VTK output to SALOME log window --- src/PVGUI/Makefile.am | 4 +- src/PVGUI/PVGUI_OutputWindowAdapter.cxx | 84 +++++++++++++++++++++++++ src/PVGUI/PVGUI_OutputWindowAdapter.h | 48 ++++++++++++++ src/PVGUI/PVGUI_ProcessModuleHelper.cxx | 34 +++++----- src/PVGUI/PVGUI_ProcessModuleHelper.h | 7 ++- 5 files changed, 161 insertions(+), 16 deletions(-) create mode 100644 src/PVGUI/PVGUI_OutputWindowAdapter.cxx create mode 100644 src/PVGUI/PVGUI_OutputWindowAdapter.h diff --git a/src/PVGUI/Makefile.am b/src/PVGUI/Makefile.am index 5bc31639..aab4b1e1 100644 --- a/src/PVGUI/Makefile.am +++ b/src/PVGUI/Makefile.am @@ -42,7 +42,9 @@ dist_libPARAVIS_la_SOURCES = \ PVGUI_ViewModel.h \ PVGUI_ViewModel.cxx \ PVGUI_ViewWindow.h \ - PVGUI_ViewWindow.cxx + PVGUI_ViewWindow.cxx \ + PVGUI_OutputWindowAdapter.h \ + PVGUI_OutputWindowAdapter.cxx # MOC pre-processing MOC_FILES = \ diff --git a/src/PVGUI/PVGUI_OutputWindowAdapter.cxx b/src/PVGUI/PVGUI_OutputWindowAdapter.cxx new file mode 100644 index 00000000..2fb78e18 --- /dev/null +++ b/src/PVGUI/PVGUI_OutputWindowAdapter.cxx @@ -0,0 +1,84 @@ + +#include "PVGUI_OutputWindowAdapter.h" + +#include + +#include +#include +#include + +vtkStandardNewMacro(PVGUI_OutputWindowAdapter); +vtkCxxRevisionMacro(PVGUI_OutputWindowAdapter, "$Revision$"); + +PVGUI_OutputWindowAdapter::PVGUI_OutputWindowAdapter() : + TextCount(0), + ErrorCount(0), + WarningCount(0), + GenericWarningCount(0) +{ +} + +PVGUI_OutputWindowAdapter::~PVGUI_OutputWindowAdapter() +{ +} + +const unsigned int PVGUI_OutputWindowAdapter::getTextCount() +{ + return this->TextCount; +} + +const unsigned int PVGUI_OutputWindowAdapter::getErrorCount() +{ + return this->ErrorCount; +} + +const unsigned int PVGUI_OutputWindowAdapter::getWarningCount() +{ + return this->WarningCount; +} + +const unsigned int PVGUI_OutputWindowAdapter::getGenericWarningCount() +{ + return this->GenericWarningCount; +} + +static LogWindow* getLogWindow() +{ + LogWindow* wnd = 0; + LightApp_Application* anApp = dynamic_cast( SUIT_Session::session()->activeApplication() ); + if ( anApp ) + wnd = anApp->logWindow(); + return wnd; +} + +void PVGUI_OutputWindowAdapter::DisplayText(const char* text) +{ + ++this->TextCount; + LogWindow* wnd = getLogWindow(); + if ( wnd ) + wnd->putMessage( text, Qt::darkGreen, LogWindow::DisplayNormal ); +} + +void PVGUI_OutputWindowAdapter::DisplayErrorText(const char* text) +{ + ++this->ErrorCount; + LogWindow* wnd = getLogWindow(); + if ( wnd ) + wnd->putMessage( text, Qt::darkRed, LogWindow::DisplayNormal ); +} + +void PVGUI_OutputWindowAdapter::DisplayWarningText(const char* text) +{ + ++this->WarningCount; + LogWindow* wnd = getLogWindow(); + if ( wnd ) + wnd->putMessage( text, Qt::black, LogWindow::DisplayNormal ); +} + +void PVGUI_OutputWindowAdapter::DisplayGenericWarningText(const char* text) +{ + ++this->GenericWarningCount; + LogWindow* wnd = getLogWindow(); + if ( wnd ) + wnd->putMessage( text, Qt::black, LogWindow::DisplayNormal ); +} diff --git a/src/PVGUI/PVGUI_OutputWindowAdapter.h b/src/PVGUI/PVGUI_OutputWindowAdapter.h new file mode 100644 index 00000000..cb79671a --- /dev/null +++ b/src/PVGUI/PVGUI_OutputWindowAdapter.h @@ -0,0 +1,48 @@ + + +#ifndef _PVGUI_OutputWindowAdapter_h +#define _PVGUI_OutputWindowAdapter_h + +#include + +/*! +vtkOutputWindow implementation that puts VTK output messages to SALOME log window. + +To use, create an instance of PVGUI_OutputWindowAdapter and pass it to the +vtkOutputWindow::setInstance() static method. + +This class is based on pqOutputWindow ParaView class. +*/ +class PVGUI_OutputWindowAdapter : public vtkOutputWindow +{ +public: + static PVGUI_OutputWindowAdapter *New(); + vtkTypeRevisionMacro(PVGUI_OutputWindowAdapter, vtkOutputWindow); + + //! Returns the number of text messages received + const unsigned int getTextCount(); + //! Returns the number of error messages received + const unsigned int getErrorCount(); + //! Returns the number of warning messages received + const unsigned int getWarningCount(); + //! Returns the number of generic warning messages received + const unsigned int getGenericWarningCount(); + +private: + PVGUI_OutputWindowAdapter(); + PVGUI_OutputWindowAdapter(const PVGUI_OutputWindowAdapter&); + PVGUI_OutputWindowAdapter& operator=(const PVGUI_OutputWindowAdapter&); + ~PVGUI_OutputWindowAdapter(); + + unsigned int TextCount; + unsigned int ErrorCount; + unsigned int WarningCount; + unsigned int GenericWarningCount; + + virtual void DisplayText(const char*); + virtual void DisplayErrorText(const char*); + virtual void DisplayWarningText(const char*); + virtual void DisplayGenericWarningText(const char*); +}; + +#endif // !_PVGUI_OutputWindowAdapter_h diff --git a/src/PVGUI/PVGUI_ProcessModuleHelper.cxx b/src/PVGUI/PVGUI_ProcessModuleHelper.cxx index cf03dc25..213bdab6 100644 --- a/src/PVGUI/PVGUI_ProcessModuleHelper.cxx +++ b/src/PVGUI/PVGUI_ProcessModuleHelper.cxx @@ -5,16 +5,32 @@ #include "PVGUI_ProcessModuleHelper.h" +#include "PVGUI_OutputWindowAdapter.h" -//#include #include -//#include +#include +#include vtkStandardNewMacro(PVGUI_ProcessModuleHelper); vtkCxxRevisionMacro(PVGUI_ProcessModuleHelper, "$Revision$"); +class PVGUI_ProcessModuleHelper::pqImplementation +{ +public: + pqImplementation() : + OutputWindowAdapter(vtkSmartPointer::New()) + {} + + ~pqImplementation() + {} + + //! Displays VTK debug output in SALOME log window + vtkSmartPointer OutputWindowAdapter; +}; + //----------------------------------------------------------------------------- PVGUI_ProcessModuleHelper::PVGUI_ProcessModuleHelper() + : Implementation(new pqImplementation()) { } @@ -62,18 +78,8 @@ void PVGUI_ProcessModuleHelper::hideWindow() int PVGUI_ProcessModuleHelper::InitializeApplication(int argc, char** argv) { if ( pqProcessModuleGUIHelper::InitializeApplication( argc, argv ) ){ - // TODO: Redirect VTK debug output to SALOME GUI message console ... - /*this->Implementation->OutputWindow = new pqOutputWindow(0); - this->Implementation->OutputWindow->setAttribute(Qt::WA_QuitOnClose, false); - this->Implementation->OutputWindow->connect(this->Implementation->OutputWindowAdapter, - SIGNAL(displayText(const QString&)), SLOT(onDisplayText(const QString&))); - this->Implementation->OutputWindow->connect(this->Implementation->OutputWindowAdapter, - SIGNAL(displayErrorText(const QString&)), SLOT(onDisplayErrorText(const QString&))); - this->Implementation->OutputWindow->connect(this->Implementation->OutputWindowAdapter, - SIGNAL(displayWarningText(const QString&)), SLOT(onDisplayWarningText(const QString&))); - this->Implementation->OutputWindow->connect(this->Implementation->OutputWindowAdapter, - SIGNAL(displayGenericWarningText(const QString&)), SLOT(onDisplayGenericWarningText(const QString&))); - vtkOutputWindow::SetInstance(Implementation->OutputWindowAdapter);*/ + // Redirect VTK debug output to SALOME GUI message console + vtkOutputWindow::SetInstance(Implementation->OutputWindowAdapter); } return 1; diff --git a/src/PVGUI/PVGUI_ProcessModuleHelper.h b/src/PVGUI/PVGUI_ProcessModuleHelper.h index 0206e411..5550d096 100644 --- a/src/PVGUI/PVGUI_ProcessModuleHelper.h +++ b/src/PVGUI/PVGUI_ProcessModuleHelper.h @@ -44,7 +44,6 @@ public: vtkTypeRevisionMacro(PVGUI_ProcessModuleHelper, pqProcessModuleGUIHelper); void PrintSelf(ostream& os, vtkIndent indent); - //! Compares the contents of the window with the given reference image, returns true iff they "match" within some tolerance virtual bool compareView(const QString& ReferenceImage, double Threshold, ostream& Output, const QString& TempDirectory); @@ -78,9 +77,15 @@ protected: //! Called by vtkProcessModule, but we cannot exit here. virtual void ExitApplication(); + //! Returns the number of errors registered in the OutputWindow + //virtual int ErrorCount(); + private: PVGUI_ProcessModuleHelper(const PVGUI_ProcessModuleHelper&); // Not implemented. void operator=(const PVGUI_ProcessModuleHelper&); // Not implemented. + + class pqImplementation; + pqImplementation* const Implementation; }; #endif -- 2.39.2