From: vsr Date: Fri, 19 Oct 2018 07:45:09 +0000 (+0300) Subject: 0022856: EDF 9971 PARAVIS: Error message not displayed in Paravis X-Git-Tag: V9_2_0a2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6a061a6658400468c5823787246a1960cf7ac1f4;p=modules%2Fgui.git 0022856: EDF 9971 PARAVIS: Error message not displayed in Paravis - Refactor paraview output messages handling in PVViewer --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index ae03b893e..c240120a6 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -1654,7 +1654,7 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType viewMgr->getActiveView()->setFocus(); return 0; } else { - viewMgr = new PVViewer_ViewManager( activeStudy(), desktop(), logWindow() ); + viewMgr = new PVViewer_ViewManager( activeStudy(), desktop() ); } } #endif @@ -2186,6 +2186,7 @@ QWidget* LightApp_Application::createWindow( const int flag ) else if ( flag == WT_LogWindow ) { LogWindow* logWin = new LogWindow( desktop() ); + logWin->handleQtMessages( true ); logWin->setObjectName( "logWindow" ); logWin->setWindowTitle( tr( "LOG_WINDOW" ) ); logWin->setProperty( "shortcut", QKeySequence( "Alt+Shift+L" ) ); diff --git a/src/LogWindow/LogWindow.cxx b/src/LogWindow/LogWindow.cxx index 84fbefd29..25e2dc86b 100755 --- a/src/LogWindow/LogWindow.cxx +++ b/src/LogWindow/LogWindow.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -43,29 +44,32 @@ #define DEFAULT_SEPARATOR "***" -/*! - \brief Convert rich text to plain text. - \internal - \param richText rich text string - \return converted plain text string -*/ -static QString plainText( const QString& richText ) +namespace { - QString aText = richText; - int startTag = aText.indexOf( '<' ); - while ( true ) + /*! + \brief Convert rich text to plain text. + \internal + \param richText rich text string + \return converted plain text string + */ + QString plainText( const QString& richText ) { - if ( startTag < 0 ) - break; - - int finishTag = aText.indexOf( '>', startTag ); - if ( finishTag < 0 ) - break; - - aText = aText.remove( startTag, finishTag - startTag + 1 ); - startTag = aText.indexOf( '<' ); + QString aText = richText; + int startTag = aText.indexOf( '<' ); + while ( true ) + { + if ( startTag < 0 ) + break; + + int finishTag = aText.indexOf( '>', startTag ); + if ( finishTag < 0 ) + break; + + aText = aText.remove( startTag, finishTag - startTag + 1 ); + startTag = aText.indexOf( '<' ); + } + return aText; } - return aText; } /*! @@ -88,8 +92,7 @@ static QString plainText( const QString& richText ) \param parent parent widget */ LogWindow::LogWindow( QWidget* parent ) -: QWidget( parent ), - SUIT_PopupClient() + : QWidget( parent ), SUIT_PopupClient(), QtxMsgHandlerCallback( false ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); @@ -100,13 +103,12 @@ LogWindow::LogWindow( QWidget* parent ) myView = new QTextEdit( this ); myView->setReadOnly( true ); myView->viewport()->installEventFilter( this ); + myView->setPlaceholderText( "Message Log" ); QVBoxLayout* main = new QVBoxLayout( this ); main->setMargin( 0 ); main->addWidget( myView ); - myBannerSize = 0; - myBanner = "Message Log\n********************"; mySeparator = DEFAULT_SEPARATOR; clear(); @@ -124,12 +126,12 @@ LogWindow::~LogWindow() } /*! - \brief Get current banner (message log window header text). + \brief Get current banner (text shown when log window is empty). \return string representing the current banner */ QString LogWindow::banner() const { - return myBanner; + return myView->placeholderText(); } /*! @@ -142,14 +144,12 @@ QString LogWindow::separator() const } /*! - \brief Set current banner (message log window header text). + \brief Set current banner (text shown when log window is empty). \param banner new banner */ void LogWindow::setBanner( const QString& banner ) { - myBanner = banner; - - clear( false ); + myView->setPlaceholderText( banner ); } /*! @@ -229,17 +229,35 @@ void LogWindow::putMessage( const QString& message, const QColor& color, const i if ( !dateTime.isEmpty() ) msg = QString( "[%1] %2" ).arg( dateTime ).arg( msg ); - myView->append( msg ); + append( msg ); myHistory.append( plainText( message ) ); if ( flags & DisplaySeparator && !mySeparator.isEmpty() ) { - myView->append( mySeparator ); // add separator + // add separator + append( mySeparator ); myHistory.append( plainText( mySeparator ) ); } myView->moveCursor( QTextCursor::End ); } +/*! + \brief Append text to the log window. + \param text Text being added. +*/ +void LogWindow::append( const QString text ) +{ + if ( !text.isEmpty() ) + { + myView->append( text ); + QTextBlock block = myView->document()->lastBlock(); + QTextCursor cursor( block ); + QTextBlockFormat format = cursor.blockFormat(); + format.setBottomMargin( 10 ); + cursor.setBlockFormat( format ); + } +} + /*! \brief Clear message log. \param clearHistory if True, clear also the messages history @@ -249,14 +267,6 @@ void LogWindow::clear( bool clearHistory ) myView->clear(); if ( clearHistory ) myHistory.clear(); - - if ( !myBanner.isEmpty() ) - { - myView->append( myBanner ); - myBannerSize = myView->document()->blockCount(); - } - else - myBannerSize = 0; } /*! @@ -340,7 +350,7 @@ void LogWindow::contextMenuPopup( QMenu* popup ) void LogWindow::updateActions() { myActions[CopyId]->setEnabled( myView->textCursor().hasSelection() ); - myActions[ ClearId ]->setEnabled( myView->document()->blockCount() > myBannerSize ); + myActions[ ClearId ]->setEnabled( !myView->document()->isEmpty() ); myActions[SelectAllId]->setEnabled( !myView->document()->isEmpty() ); myActions[ SaveToFileId ]->setEnabled( myHistory.count() > 0 ); } @@ -426,6 +436,49 @@ int LogWindow::menuActions() const return ret; } +/*! + \brief Activate/deactivate Qt messages handling. + \param on If \c true, Qt messags are handled by log window. +*/ +void LogWindow::handleQtMessages(bool on) +{ + if ( on ) + activate(); + else + deactivate(); +} + +/*! + \brief Handle Qt messages. + \param type Qt message type. + \param context Message context. + \param message Message text. +*/ +void LogWindow::qtMessage( QtMsgType type, const QMessageLogContext&, const QString& message ) +{ + QColor color; + switch ( type ) + { + case QtInfoMsg: + color = QColor("#008000"); // dark green + break; + case QtCriticalMsg: + color = QColor("#ff0000"); // red + break; + case QtFatalMsg: + color = QColor("#800000"); // dark red + break; + case QtWarningMsg: + color = QColor("#ff9000"); // orange + break; + case QtDebugMsg: + default: + color = QColor("#000000"); // black + break; + } + putMessage( message, color, DisplayNormal); +} + /*! \fn virtual QString LogWindow::popupClientType() const; \brief Get popup client symbolic name, used in popup menu management system. diff --git a/src/LogWindow/LogWindow.h b/src/LogWindow/LogWindow.h index a15937859..a150c1e78 100755 --- a/src/LogWindow/LogWindow.h +++ b/src/LogWindow/LogWindow.h @@ -37,7 +37,8 @@ # define LOGWINDOW_EXPORT #endif -#include +#include "QtxMsgHandler.h" +#include "SUIT_PopupClient.h" #include #include @@ -50,7 +51,7 @@ class QAction; class QTextEdit; -class LOGWINDOW_EXPORT LogWindow : public QWidget, public SUIT_PopupClient +class LOGWINDOW_EXPORT LogWindow : public QWidget, public SUIT_PopupClient, public QtxMsgHandlerCallback { Q_OBJECT @@ -77,7 +78,7 @@ public: }; public: - LogWindow( QWidget* theParent ); + LogWindow( QWidget* ); virtual ~LogWindow(); virtual QString popupClientType() const { return QString( "LogWindow" ); } @@ -100,6 +101,8 @@ public: void setMenuActions( const int ); int menuActions() const; + void handleQtMessages(bool); + protected slots: void onSaveToFile(); void onSelectAll(); @@ -107,8 +110,10 @@ protected slots: void onCopy(); private: + void append( const QString text ); void createActions(); void updateActions(); + void qtMessage( QtMsgType, const QMessageLogContext&, const QString& ); private: QTextEdit* myView; //!< internal view window diff --git a/src/PVViewer/CMakeLists.txt b/src/PVViewer/CMakeLists.txt index 05910b481..0e3a19dd6 100644 --- a/src/PVViewer/CMakeLists.txt +++ b/src/PVViewer/CMakeLists.txt @@ -25,13 +25,9 @@ INCLUDE(UseQtExt) # --- options --- INCLUDE_DIRECTORIES( - ${PROJECT_SOURCE_DIR}/src/SUIT - ${PROJECT_SOURCE_DIR}/src/STD ${PROJECT_SOURCE_DIR}/src/Qtx - ${PROJECT_SOURCE_DIR}/src/Event - ${PROJECT_SOURCE_DIR}/src/PyInterp + ${PROJECT_SOURCE_DIR}/src/SUIT ${PROJECT_SOURCE_DIR}/src/PVServerService - ${CMAKE_SOURCE_DIR}/src/LogWindow ) ADD_DEFINITIONS( @@ -42,9 +38,7 @@ ADD_DEFINITIONS( SET(_link_LIBRARIES ${KERNEL_SALOMELocalTrace} ${KERNEL_OpUtil} - PyInterp suit - Event PVServerService pqApplicationComponents #vtkRenderingFreeTypeOpenGL @@ -67,7 +61,7 @@ SET(_moc_HEADERS # header files / no moc processing SET(_other_HEADERS PVViewer.h - PVViewer_LogWindowAdapter.h + PVViewer_OutputWindow.h PVViewer_Core.h ) # header files / to install @@ -93,7 +87,7 @@ SET(_other_SOURCES PVViewer_ViewManager.cxx PVViewer_ViewModel.cxx PVViewer_ViewWindow.cxx - PVViewer_LogWindowAdapter.cxx + PVViewer_OutputWindow.cxx PVViewer_Behaviors.cxx PVViewer_GUIElements.cxx PVViewer_Core.cxx diff --git a/src/PVViewer/PVViewer.h b/src/PVViewer/PVViewer.h index 4959685ce..8db5a578d 100644 --- a/src/PVViewer/PVViewer.h +++ b/src/PVViewer/PVViewer.h @@ -21,13 +21,13 @@ #define PVVIEWER_H #ifdef WIN32 -#if defined PVViewer_EXPORTS -#define PVVIEWER_EXPORT __declspec(dllexport) +# if defined PVVIEWER_EXPORTS || defined PVViewer_EXPORTS +# define PVVIEWER_EXPORT __declspec(dllexport) +# else +# define PVVIEWER_EXPORT __declspec(dllimport) +# endif #else -#define PVVIEWER_EXPORT __declspec(dllimport) -#endif -#else -#define PVVIEWER_EXPORT +# define PVVIEWER_EXPORT #endif -#endif //PVVIEWER_H +#endif // PVVIEWER_H diff --git a/src/PVViewer/PVViewer_Behaviors.h b/src/PVViewer/PVViewer_Behaviors.h index 8eb1665fd..9f7d71aa2 100644 --- a/src/PVViewer/PVViewer_Behaviors.h +++ b/src/PVViewer/PVViewer_Behaviors.h @@ -19,8 +19,8 @@ // Author: Adrien Bruneton (CEA) -#ifndef PVGUIBEHAVIORS_H_ -#define PVGUIBEHAVIORS_H_ +#ifndef PVVIEWER_BEHAVIORS_H +#define PVVIEWER_BEHAVIORS_H #include "PVViewer.h" @@ -39,10 +39,10 @@ class PVVIEWER_EXPORT PVViewer_Behaviors: public QObject Q_OBJECT public: - PVViewer_Behaviors(QMainWindow * parent); + PVViewer_Behaviors(QMainWindow*); - void instanciateMinimalBehaviors(QMainWindow * desk); - void instanciateAllBehaviors(QMainWindow * desk); + void instanciateMinimalBehaviors(QMainWindow*); + void instanciateAllBehaviors(QMainWindow*); virtual ~PVViewer_Behaviors() {} @@ -50,4 +50,4 @@ private: static int BehaviorLoadingLevel; }; -#endif /* PVGUIBEHAVIORS_H_ */ +#endif // PVVIEWER_BEHAVIORS_H diff --git a/src/PVViewer/PVViewer_Core.cxx b/src/PVViewer/PVViewer_Core.cxx index 6e9e69203..c249d8a67 100644 --- a/src/PVViewer/PVViewer_Core.cxx +++ b/src/PVViewer/PVViewer_Core.cxx @@ -20,7 +20,7 @@ // #include "PVViewer_Core.h" -#include "PVViewer_LogWindowAdapter.h" +#include "PVViewer_OutputWindow.h" #include "PVViewer_GUIElements.h" #include "PVViewer_Behaviors.h" #include "PVViewer_Core.h" @@ -58,7 +58,7 @@ pqPVApplicationCore * PVViewer_Core::GetPVApplication() \param fullSetup whether to instanciate all behaviors or just the minimal ones. \return \c true if ParaView has been initialized successfully, otherwise false */ -bool PVViewer_Core::ParaviewInitApp(QMainWindow * aDesktop, LogWindow * logWindow) +bool PVViewer_Core::ParaviewInitApp(QMainWindow * aDesktop) { if ( ! MyCoreApp) { // Obtain command-line arguments @@ -103,8 +103,7 @@ bool PVViewer_Core::ParaviewInitApp(QMainWindow * aDesktop, LogWindow * logWindo } // Direct VTK log messages to our SALOME window - TODO: review this - PVViewer_LogWindowAdapter * w = PVViewer_LogWindowAdapter::New(); - w->setLogWindow(logWindow); + PVViewer_OutputWindow * w = PVViewer_OutputWindow::New(); vtkOutputWindow::SetInstance(w); new pqTabbedMultiViewWidget(); // registers a "MULTIVIEW_WIDGET" on creation diff --git a/src/PVViewer/PVViewer_Core.h b/src/PVViewer/PVViewer_Core.h index 28e0ba3e3..7c66b015c 100644 --- a/src/PVViewer/PVViewer_Core.h +++ b/src/PVViewer/PVViewer_Core.h @@ -18,8 +18,8 @@ // // Author : Adrien Bruneton (CEA) -#ifndef SRC_PVVIEWER_PVVIEWER_CORE_H_ -#define SRC_PVVIEWER_PVVIEWER_CORE_H_ +#ifndef PVVIEWER_CORE_H +#define PVVIEWER_CORE_H #include "PVViewer.h" @@ -27,7 +27,6 @@ class PVServer_ServiceWrapper; class PVViewer_Behaviors; -class LogWindow; class QMainWindow; class pqPVApplicationCore; @@ -38,14 +37,13 @@ class pqPVApplicationCore; class PVVIEWER_EXPORT PVViewer_Core { public: - static pqPVApplicationCore * GetPVApplication(); - + static pqPVApplicationCore* GetPVApplication(); //! Initialize ParaView if not yet done (once per session) - static bool ParaviewInitApp(QMainWindow* aDesktop, LogWindow * w); - static void ParaviewInitBehaviors(bool fullSetup=false, QMainWindow* aDesktop=0); - static void ParaviewLoadConfigurations(const QString & configPath, bool force=false); - static void ParaviewCleanup(); + static bool ParaviewInitApp(QMainWindow*); + static void ParaviewInitBehaviors(bool = false, QMainWindow* = 0); + static void ParaviewLoadConfigurations(const QString&, bool = false); + static void ParaviewCleanup(); private: PVViewer_Core(); @@ -53,7 +51,7 @@ private: static pqPVApplicationCore* MyCoreApp; static bool ConfigLoaded; - static PVViewer_Behaviors * ParaviewBehaviors; + static PVViewer_Behaviors* ParaviewBehaviors; }; -#endif /* SRC_PVVIEWER_PVVIEWER_CORE_H_ */ +#endif // PVVIEWER_CORE_H diff --git a/src/PVViewer/PVViewer_GUIElements.cxx b/src/PVViewer/PVViewer_GUIElements.cxx index 6026eb462..79f25db34 100644 --- a/src/PVViewer/PVViewer_GUIElements.cxx +++ b/src/PVViewer/PVViewer_GUIElements.cxx @@ -61,8 +61,7 @@ PVViewer_GUIElements * PVViewer_GUIElements::theInstance = 0; -PVViewer_GUIElements::PVViewer_GUIElements(QMainWindow* desk) : - myDesktop(desk), +PVViewer_GUIElements::PVViewer_GUIElements(QMainWindow* desktop) : propertiesPanel(0), pipelineBrowserWidget(0), pipelineModel(0), @@ -70,7 +69,28 @@ PVViewer_GUIElements::PVViewer_GUIElements(QMainWindow* desk) : filtersMenu(0), macrosMenu(0), catalystMenu(0), - myPVWidgetsFlag(false) + mainToolBar(0), + vcrToolbar(0), + timeToolbar(0), + colorToolbar(0), + reprToolbar(0), + cameraToolbar(0), + axesToolbar(0), + macrosToolbar(0), + commonToolbar(0), + dataToolbar(0), + myDesktop(desktop), + myPVWidgetsFlag(false), + mainAction(0), + vcrAction(0), + timeAction(0), + colorAction(0), + reprAction(0), + cameraAction(0), + axesAction(0), + macrosAction(0), + commonAction(0), + dataAction(0) { } diff --git a/src/PVViewer/PVViewer_GUIElements.h b/src/PVViewer/PVViewer_GUIElements.h index 57c2e735e..9d6463626 100644 --- a/src/PVViewer/PVViewer_GUIElements.h +++ b/src/PVViewer/PVViewer_GUIElements.h @@ -18,22 +18,22 @@ // // Author: Adrien Bruneton (CEA) -#ifndef PVVIEWERGUIELEMENTS_H_ -#define PVVIEWERGUIELEMENTS_H_ +#ifndef PVVIEWER_GUIELEMENTS_H +#define PVVIEWER_GUIELEMENTS_H #include "PVViewer.h" #include #include -class pqPropertiesPanel; -class pqPipelineBrowserWidget; -class pqPipelineModel; +class QAction; class QMainWindow; class QMenu; class QToolBar; -class QAction; class pqAnimationTimeToolbar; +class pqPipelineBrowserWidget; +class pqPipelineModel; +class pqPropertiesPanel; class pqVCRToolbar; /*! @@ -45,10 +45,10 @@ class PVVIEWER_EXPORT PVViewer_GUIElements: public QObject Q_OBJECT public: - static PVViewer_GUIElements * GetInstance(QMainWindow * desk); + static PVViewer_GUIElements* GetInstance(QMainWindow*); - pqPropertiesPanel * getPropertiesPanel(); - pqPipelineBrowserWidget * getPipelineBrowserWidget(); + pqPropertiesPanel* getPropertiesPanel(); + pqPipelineBrowserWidget* getPipelineBrowserWidget(); QMenu* getFiltersMenu(); QMenu* getSourcesMenu(); @@ -58,14 +58,14 @@ public: pqVCRToolbar* getVCRToolbar(); pqAnimationTimeToolbar* getTimeToolbar(); - void setToolBarVisible(bool show); - void setToolBarEnabled(bool enabled); + void setToolBarVisible(bool); + void setToolBarEnabled(bool); QList getToolbars(); - void setVCRTimeToolBarVisible(bool show); + void setVCRTimeToolBarVisible(bool); private: - PVViewer_GUIElements(QMainWindow* desk); + PVViewer_GUIElements(QMainWindow*); virtual ~PVViewer_GUIElements() {} static PVViewer_GUIElements* theInstance; @@ -98,7 +98,7 @@ private: QToolBar* dataToolbar; QMainWindow* myDesktop; - bool myPVWidgetsFlag; + bool myPVWidgetsFlag; public: QAction* mainAction; @@ -113,4 +113,4 @@ public: QAction* dataAction; }; -#endif /* PVVIEWERGUIELEMENTS_H_ */ +#endif // PVVIEWER_GUIELEMENTS_H diff --git a/src/PVViewer/PVViewer_InitSingleton.cxx b/src/PVViewer/PVViewer_InitSingleton.cxx index 538e0d085..e329b498e 100644 --- a/src/PVViewer/PVViewer_InitSingleton.cxx +++ b/src/PVViewer/PVViewer_InitSingleton.cxx @@ -24,15 +24,15 @@ bool PVViewer_InitSingleton::IS_INIT=false; -void PVViewer_InitSingleton::Init(QMainWindow *aDesktop, LogWindow *logWindow) +void PVViewer_InitSingleton::Init(QMainWindow* desktop) { if(IS_INIT) return ; - PVViewer_Core::ParaviewInitApp(aDesktop,logWindow); + PVViewer_Core::ParaviewInitApp(desktop); // Finish ParaView set up: behaviors, connection and configurations. const QString configPath(PVViewer_ViewManager::GetPVConfigPath()); - PVViewer_Core::ParaviewInitBehaviors(true,aDesktop); - PVViewer_ViewManager::ConnectToExternalPVServer(aDesktop); + PVViewer_Core::ParaviewInitBehaviors(true, desktop); + PVViewer_ViewManager::ConnectToExternalPVServer(desktop); PVViewer_Core::ParaviewLoadConfigurations(configPath); IS_INIT=true; } diff --git a/src/PVViewer/PVViewer_InitSingleton.h b/src/PVViewer/PVViewer_InitSingleton.h index 93eba85b5..af8d884c0 100644 --- a/src/PVViewer/PVViewer_InitSingleton.h +++ b/src/PVViewer/PVViewer_InitSingleton.h @@ -18,13 +18,12 @@ // // Author : Anthony GEAY (EDF R&D) -#ifndef __PVVIEWER_INITSINGLETON_H__ -#define __PVVIEWER_INITSINGLETON_H__ +#ifndef PVVIEWER_INITSINGLETON_H +#define PVVIEWER_INITSINGLETON_H #include "PVViewer.h" class QMainWindow; -class LogWindow; /** * This class deals with initialization of SALOME_Session to make it a PV based application. @@ -34,9 +33,9 @@ class LogWindow; class PVVIEWER_EXPORT PVViewer_InitSingleton { public: - static void Init(QMainWindow *aDesktop, LogWindow *logWindow); + static void Init(QMainWindow*); private: static bool IS_INIT; }; -#endif /* SRC_PVVIEWER_PVVIEWER_CORE_H_ */ +#endif // PVVIEWER_INITSINGLETON_H diff --git a/src/PVViewer/PVViewer_LogWindowAdapter.cxx b/src/PVViewer/PVViewer_LogWindowAdapter.cxx deleted file mode 100644 index 78fb6af7f..000000000 --- a/src/PVViewer/PVViewer_LogWindowAdapter.cxx +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (C) 2014-2016 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include "PVViewer_LogWindowAdapter.h" - -#include - -#include -#include -#include -#include - -vtkStandardNewMacro(PVViewer_LogWindowAdapter); - -/*! - * Put the message in the log window. - */ -class TEvent: public SALOME_Event { - LogWindow* myWindow; - QString myMsg; - QColor myColor; - int myFlags; - public: - TEvent( LogWindow* theWindow, const QString theMsg, const QColor theColor, const int flags) : - myWindow ( theWindow ), - myMsg ( theMsg ), - myColor ( theColor ), - myFlags (flags) - {} - - virtual void Execute() { - if(myWindow) - myWindow->putMessage(myMsg, myColor, myFlags); - } -}; - - -PVViewer_LogWindowAdapter::PVViewer_LogWindowAdapter() : - TextCount(0), - ErrorCount(0), - WarningCount(0), - GenericWarningCount(0), - logWindow(0) -{ -} - -PVViewer_LogWindowAdapter::~PVViewer_LogWindowAdapter() -{ -} - -const unsigned int PVViewer_LogWindowAdapter::getTextCount() -{ - return this->TextCount; -} - -const unsigned int PVViewer_LogWindowAdapter::getErrorCount() -{ - return this->ErrorCount; -} - -const unsigned int PVViewer_LogWindowAdapter::getWarningCount() -{ - return this->WarningCount; -} - -const unsigned int PVViewer_LogWindowAdapter::getGenericWarningCount() -{ - return this->GenericWarningCount; -} - -void PVViewer_LogWindowAdapter::DisplayText(const char* text) -{ - ++this->TextCount; - ProcessVoidEvent( new TEvent( getLogWindow(), text, Qt::darkGreen, LogWindow::DisplayNormal )); -} - -void PVViewer_LogWindowAdapter::DisplayErrorText(const char* text) -{ - ++this->ErrorCount; - ProcessVoidEvent( new TEvent( getLogWindow(), text, Qt::darkRed, LogWindow::DisplayNormal )); -} - -void PVViewer_LogWindowAdapter::DisplayWarningText(const char* text) -{ - ++this->WarningCount; - ProcessVoidEvent( new TEvent( getLogWindow(), text, Qt::black, LogWindow::DisplayNormal )); -} - -void PVViewer_LogWindowAdapter::DisplayGenericWarningText(const char* text) -{ - ++this->GenericWarningCount; - ProcessVoidEvent( new TEvent( getLogWindow() , text, Qt::black, LogWindow::DisplayNormal )); -} diff --git a/src/PVViewer/PVViewer_LogWindowAdapter.h b/src/PVViewer/PVViewer_LogWindowAdapter.h deleted file mode 100644 index 9be72e2ac..000000000 --- a/src/PVViewer/PVViewer_LogWindowAdapter.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2014-2016 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef _PVViewer_LogWindowAdapter_h -#define _PVViewer_LogWindowAdapter_h - -#include "PVViewer.h" - -#include - -class LogWindow; - -/*! -vtkOutputWindow implementation that puts VTK output messages to SALOME log window. - -To use, create an instance of PVViewer_LogWindowAdapter and pass it to the -vtkOutputWindow::setInstance() static method. - -This class is based on pqOutputWindow ParaView class. -*/ -class PVVIEWER_EXPORT PVViewer_LogWindowAdapter : public vtkOutputWindow -{ -public: - static PVViewer_LogWindowAdapter *New(); - vtkTypeMacro(PVViewer_LogWindowAdapter, 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(); - - void setLogWindow( LogWindow* w) { logWindow = w; } - LogWindow* getLogWindow() { return logWindow; } - -private: - PVViewer_LogWindowAdapter(); - PVViewer_LogWindowAdapter(const PVViewer_LogWindowAdapter&); - PVViewer_LogWindowAdapter& operator=(const PVViewer_LogWindowAdapter&); - ~PVViewer_LogWindowAdapter(); - - unsigned int TextCount; - unsigned int ErrorCount; - unsigned int WarningCount; - unsigned int GenericWarningCount; - LogWindow * logWindow; - - virtual void DisplayText(const char*); - virtual void DisplayErrorText(const char*); - virtual void DisplayWarningText(const char*); - virtual void DisplayGenericWarningText(const char*); -}; - -#endif // !_PVViewer_LogWindowAdapter_h diff --git a/src/PVViewer/PVViewer_OutputWindow.cxx b/src/PVViewer/PVViewer_OutputWindow.cxx new file mode 100644 index 000000000..ebef841f4 --- /dev/null +++ b/src/PVViewer/PVViewer_OutputWindow.cxx @@ -0,0 +1,85 @@ +// Copyright (C) 2014-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "PVViewer_OutputWindow.h" + +#include + +vtkStandardNewMacro(PVViewer_OutputWindow); + +PVViewer_OutputWindow::PVViewer_OutputWindow() +{ +} + +PVViewer_OutputWindow::~PVViewer_OutputWindow() +{ +} + +const unsigned int PVViewer_OutputWindow::getTextCount() +{ + return count(MESSAGE_TYPE_TEXT); +} + +const unsigned int PVViewer_OutputWindow::getErrorCount() +{ + return count(MESSAGE_TYPE_ERROR); +} + +const unsigned int PVViewer_OutputWindow::getWarningCount() +{ + return count(MESSAGE_TYPE_WARNING); +} + +const unsigned int PVViewer_OutputWindow::getGenericWarningCount() +{ + return count(MESSAGE_TYPE_GENERIC_WARNING); +} + +const unsigned int PVViewer_OutputWindow::getDebugCount() +{ + return count(MESSAGE_TYPE_DEBUG); +} + +void PVViewer_OutputWindow::DisplayText(const char* text) +{ + MessageTypes type = GetCurrentMessageType(); + myCounter[type] = count(type) + 1; + switch (type) + { + case MESSAGE_TYPE_ERROR: + qCritical(text); + break; + case MESSAGE_TYPE_WARNING: + case MESSAGE_TYPE_GENERIC_WARNING: + qWarning(text); + break; + case MESSAGE_TYPE_DEBUG: + qDebug(text); + break; + case MESSAGE_TYPE_TEXT: + default: + qInfo(text); + break; + } +} + +int PVViewer_OutputWindow::count(const MessageTypes& type) +{ + return myCounter.value(type, 0); +} diff --git a/src/PVViewer/PVViewer_OutputWindow.h b/src/PVViewer/PVViewer_OutputWindow.h new file mode 100644 index 000000000..fa278297d --- /dev/null +++ b/src/PVViewer/PVViewer_OutputWindow.h @@ -0,0 +1,66 @@ +// Copyright (C) 2014-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef PVVIEWER_OUTPUTWINDOW_H +#define PVVIEWER_OUTPUTWINDOW_H + +#include "PVViewer.h" + +#include +#include + +/** + vtkOutputWindow implementation that redirects VTK output messages + to dedicated sinals which are then handled by SALOME log window. + + To use, create an instance of PVViewer_OutputWindow and pass it to the + vtkOutputWindow::setInstance() static method. + + This class is based on pqOutputWindow ParaView class. + */ +class PVVIEWER_EXPORT PVViewer_OutputWindow : public vtkOutputWindow +{ +public: + static PVViewer_OutputWindow* New(); + vtkTypeMacro(PVViewer_OutputWindow, 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(); + //! Returns the number of debug messages received + const unsigned int getDebugCount(); + +private: + PVViewer_OutputWindow(); + PVViewer_OutputWindow(const PVViewer_OutputWindow&); + PVViewer_OutputWindow& operator=(const PVViewer_OutputWindow&); + ~PVViewer_OutputWindow(); + + QMap myCounter; + + void DisplayText(const char*); + int count(const MessageTypes&); +}; + +#endif // PVVIEWER_OUTPUTWINDOW_H diff --git a/src/PVViewer/PVViewer_ViewManager.cxx b/src/PVViewer/PVViewer_ViewManager.cxx index 42a794799..29eddef95 100644 --- a/src/PVViewer/PVViewer_ViewManager.cxx +++ b/src/PVViewer/PVViewer_ViewManager.cxx @@ -28,12 +28,11 @@ #include -#include -#include -#include -#include -#include -#include +#include "SUIT_Desktop.h" +#include "SUIT_Study.h" +#include "SUIT_Session.h" +#include "SUIT_MessageBox.h" +#include "SUIT_ResourceMgr.h" #include #include @@ -42,21 +41,19 @@ /*! Constructor */ -PVViewer_ViewManager::PVViewer_ViewManager( SUIT_Study* study, SUIT_Desktop* desk, LogWindow * logWindow ) -: SUIT_ViewManager( study, desk, new PVViewer_Viewer() ), - desktop(desk) +PVViewer_ViewManager::PVViewer_ViewManager(SUIT_Study* study, SUIT_Desktop* desktop) +: SUIT_ViewManager( study, desktop, new PVViewer_Viewer() ) { MESSAGE("PVViewer - view manager created ...") setTitle( tr( "PARAVIEW_VIEW_TITLE" ) ); // Initialize minimal paraview stuff (if not already done) - PVViewer_InitSingleton::Init(desk, logWindow); + PVViewer_InitSingleton::Init(desktop); - connect( desk, SIGNAL( windowActivated( SUIT_ViewWindow* ) ), + connect( desktop, SIGNAL( windowActivated( SUIT_ViewWindow* ) ), this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) ); } - PVServer_ServiceWrapper * PVViewer_ViewManager::GetService() { return PVServer_ServiceWrapper::GetInstance(); @@ -68,7 +65,7 @@ QString PVViewer_ViewManager::GetPVConfigPath() return resMgr->stringValue("resources", "PVViewer", QString()); } -bool PVViewer_ViewManager::ConnectToExternalPVServer(QMainWindow* aDesktop) +bool PVViewer_ViewManager::ConnectToExternalPVServer(QMainWindow* desktop) { SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); bool noConnect = aResourceMgr->booleanValue( "PARAVIS", "no_ext_pv_server", false ); @@ -77,23 +74,23 @@ bool PVViewer_ViewManager::ConnectToExternalPVServer(QMainWindow* aDesktop) pqServer* server = pqActiveObjects::instance().activeServer(); if (server && server->isRemote()) - { - // Already connected to an external server, do nothing - MESSAGE("connectToExternalPVServer(): Already connected to an external PVServer, won't reconnect."); - return false; - } + { + // Already connected to an external server, do nothing + MESSAGE("connectToExternalPVServer(): Already connected to an external PVServer, won't reconnect."); + return false; + } if (GetService()->GetGUIConnected()) - { - // Should never be there as the above should already tell us that we are connected. - std::stringstream msg2; - msg2 << "Internal error while connecting to the pvserver."; - msg2 << "ParaView doesn't see a connection, but PARAVIS engine tells us there is already one!" << std::endl; - qWarning(msg2.str().c_str()); // will go to the ParaView console (see ParavisMessageOutput below) - SUIT_MessageBox::warning( aDesktop, - QString("Error connecting to PVServer"), QString(msg2.str().c_str())); - return false; - } + { + // Should never be there as the above should already tell us that we are connected. + std::stringstream msg2; + msg2 << "Internal error while connecting to the pvserver."; + msg2 << "ParaView doesn't see a connection, but PARAVIS engine tells us there is already one!" << std::endl; + qWarning(msg2.str().c_str()); // will go to the ParaView console (see ParavisMessageOutput below) + SUIT_MessageBox::warning( desktop, + QString("Error connecting to PVServer"), QString(msg2.str().c_str())); + return false; + } std::stringstream msg; @@ -101,43 +98,44 @@ bool PVViewer_ViewManager::ConnectToExternalPVServer(QMainWindow* aDesktop) QString serverUrlEnv = getenv("PARAVIEW_PVSERVER_URL"); std::string serverUrl; if (!serverUrlEnv.isEmpty()) + { serverUrl = serverUrlEnv.toStdString(); + } else - { - // Get the URL from the engine (possibly starting the pvserver) - serverUrl = GetService()->FindOrStartPVServer(0); // take the first free port - } - + { + // Get the URL from the engine (possibly starting the pvserver) + serverUrl = GetService()->FindOrStartPVServer(0); // take the first free port + } + msg << "connectToExternalPVServer(): Trying to connect to the external PVServer '" << serverUrl << "' ..."; MESSAGE(msg.str()); if (!pqServerConnectReaction::connectToServer(pqServerResource(serverUrl.c_str()))) - { - std::stringstream msg2; - msg2 << "Error while connecting to the requested pvserver '" << serverUrl; - msg2 << "'. Might use default built-in connection instead!" << std::endl; - qWarning(msg2.str().c_str()); // will go to the ParaView console (see ParavisMessageOutput below) - SUIT_MessageBox::warning( aDesktop, - QString("Error connecting to PVServer"), QString(msg2.str().c_str())); - return false; - } + { + std::stringstream msg2; + msg2 << "Error while connecting to the requested pvserver '" << serverUrl; + msg2 << "'. Might use default built-in connection instead!" << std::endl; + qWarning(msg2.str().c_str()); // will go to the ParaView console (see ParavisMessageOutput below) + SUIT_MessageBox::warning( desktop, + QString("Error connecting to PVServer"), QString(msg2.str().c_str())); + return false; + } else - { - MESSAGE("connectToExternalPVServer(): Connected!"); - GetService()->SetGUIConnected(true); - } + { + MESSAGE("connectToExternalPVServer(): Connected!"); + GetService()->SetGUIConnected(true); + } return true; } - /*!Enable toolbars if view \a view is ParaView viewer and disable otherwise. */ void PVViewer_ViewManager::onWindowActivated(SUIT_ViewWindow* view) { if (view) - { + { PVViewer_ViewWindow* pvWindow = dynamic_cast(view); - PVViewer_GUIElements * guiElements = PVViewer_GUIElements::GetInstance(desktop); + PVViewer_GUIElements * guiElements = PVViewer_GUIElements::GetInstance( myDesktop ); guiElements->setToolBarEnabled(pvWindow!=0); - } + } } diff --git a/src/PVViewer/PVViewer_ViewManager.h b/src/PVViewer/PVViewer_ViewManager.h index 2e7404b6e..5157a2a57 100644 --- a/src/PVViewer/PVViewer_ViewManager.h +++ b/src/PVViewer/PVViewer_ViewManager.h @@ -18,17 +18,16 @@ // // Author: Adrien Bruneton (CEA) -#ifndef PVViewer_VIEWMANAGER_H -#define PVViewer_VIEWMANAGER_H +#ifndef PVVIEWER_VIEWMANAGER_H +#define PVVIEWER_VIEWMANAGER_H #include "PVViewer.h" -#include +#include "SUIT_ViewManager.h" class SUIT_Desktop; class SUIT_Study; class SUIT_ViewWindow; -class LogWindow; class PVServer_ServiceWrapper; class QMainWindow; @@ -37,24 +36,21 @@ class PVVIEWER_EXPORT PVViewer_ViewManager : public SUIT_ViewManager Q_OBJECT public: - PVViewer_ViewManager( SUIT_Study*, SUIT_Desktop*, LogWindow *); + PVViewer_ViewManager(SUIT_Study*, SUIT_Desktop*); ~PVViewer_ViewManager() {} //! Get the CORBA engine wrapper. - static PVServer_ServiceWrapper * GetService(); + static PVServer_ServiceWrapper* GetService(); //! Get PVViewer configuration path as stored by SALOME's resource manager: static QString GetPVConfigPath(); //! Connect to the external PVServer, using the PARAVIS engine to launch it if it is not //! already up. - static bool ConnectToExternalPVServer(QMainWindow* aDesktop); + static bool ConnectToExternalPVServer(QMainWindow*); protected slots: void onWindowActivated(SUIT_ViewWindow*); - -private: - SUIT_Desktop * desktop; }; -#endif +#endif // PVVIEWER_VIEWMANAGER_H diff --git a/src/PVViewer/PVViewer_ViewModel.cxx b/src/PVViewer/PVViewer_ViewModel.cxx index 4198557a2..aaacbfebd 100644 --- a/src/PVViewer/PVViewer_ViewModel.cxx +++ b/src/PVViewer/PVViewer_ViewModel.cxx @@ -22,7 +22,7 @@ #include "PVViewer_ViewWindow.h" #include -#include +#include "SUIT_Desktop.h" //---------------------------------------- PVViewer_Viewer::PVViewer_Viewer() @@ -35,9 +35,8 @@ PVViewer_Viewer::PVViewer_Viewer() Create new instance of view window on desktop \a theDesktop. \retval SUIT_ViewWindow* - created view window pointer. */ -SUIT_ViewWindow* PVViewer_Viewer::createView(SUIT_Desktop* theDesktop) +SUIT_ViewWindow* PVViewer_Viewer::createView(SUIT_Desktop* desktop) { - PVViewer_ViewWindow* aPVView = new PVViewer_ViewWindow(theDesktop, this); - return aPVView; + return new PVViewer_ViewWindow(desktop, this); } diff --git a/src/PVViewer/PVViewer_ViewModel.h b/src/PVViewer/PVViewer_ViewModel.h index e252c92c5..8533f79b6 100644 --- a/src/PVViewer/PVViewer_ViewModel.h +++ b/src/PVViewer/PVViewer_ViewModel.h @@ -18,12 +18,12 @@ // // Author: Adrien Bruneton (CEA) -#if !defined(_PVViewer_VIEWMODEL_H) -#define _PVViewer_VIEWMODEL_H +#ifndef PVVIEWER_VIEWMODEL_H +#define PVVIEWER_VIEWMODEL_H #include "PVViewer.h" -#include +#include "SUIT_ViewModel.h" class SUIT_ViewWindow; class SUIT_Desktop; @@ -37,10 +37,9 @@ public: PVViewer_Viewer(); virtual ~PVViewer_Viewer() {} - virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop); + virtual SUIT_ViewWindow* createView(SUIT_Desktop*); virtual QString getType() const { return Type(); } static QString Type() { return "ParaView"; } }; -#endif // !defined(_PVViewer_VIEWMODEL_H) - +#endif // PVVIEWER_VIEWMODEL_H diff --git a/src/PVViewer/PVViewer_ViewWindow.cxx b/src/PVViewer/PVViewer_ViewWindow.cxx index f2c7f9221..68694b81e 100644 --- a/src/PVViewer/PVViewer_ViewWindow.cxx +++ b/src/PVViewer/PVViewer_ViewWindow.cxx @@ -24,11 +24,11 @@ #include "PVViewer_GUIElements.h" #include "PVViewer_ViewManager.h" -#include -#include -#include -#include -#include +#include "SUIT_ViewManager.h" +#include "SUIT_ResourceMgr.h" +#include "SUIT_Session.h" +#include "SUIT_Desktop.h" +#include "SUIT_Application.h" #include #include @@ -117,8 +117,3 @@ pqTabbedMultiViewWidget* PVViewer_ViewWindow::getMultiViewManager() const { return myPVMgr; } - -//void PVViewer_ViewWindow::onEmulateApply() -//{ -// emit this->applyRequest(); -//} diff --git a/src/PVViewer/PVViewer_ViewWindow.h b/src/PVViewer/PVViewer_ViewWindow.h index 4f8633f9e..e75c720f7 100644 --- a/src/PVViewer/PVViewer_ViewWindow.h +++ b/src/PVViewer/PVViewer_ViewWindow.h @@ -18,13 +18,12 @@ // // Author : Adrien Bruneton (CEA) - -#ifndef PVViewer_VIEWWINDOW_H -#define PVViewer_VIEWWINDOW_H +#ifndef PVVIEWER_VIEWWINDOW_H +#define PVVIEWER_VIEWWINDOW_H #include "PVViewer.h" -#include +#include "SUIT_ViewWindow.h" #include class SUIT_Desktop; @@ -39,17 +38,17 @@ public: PVViewer_ViewWindow( SUIT_Desktop*, PVViewer_Viewer* ); virtual ~PVViewer_ViewWindow(); - virtual QString getVisualParameters(); - virtual void setVisualParameters( const QString& ); + virtual QString getVisualParameters(); + virtual void setVisualParameters( const QString& ); - pqTabbedMultiViewWidget* getMultiViewManager() const; + pqTabbedMultiViewWidget* getMultiViewManager() const; static void removePVMgr(); private: - SUIT_Desktop* myDesktop; - PVViewer_Viewer* myModel; - pqTabbedMultiViewWidget* myPVMgr; + SUIT_Desktop* myDesktop; + PVViewer_Viewer* myModel; + pqTabbedMultiViewWidget* myPVMgr; }; -#endif // PLOT2D_VIEWWINDOW_H +#endif // PVVIEWER_VIEWWINDOW_H diff --git a/src/Qtx/CMakeLists.txt b/src/Qtx/CMakeLists.txt index bca0f0dc9..b0848fe47 100755 --- a/src/Qtx/CMakeLists.txt +++ b/src/Qtx/CMakeLists.txt @@ -96,6 +96,7 @@ SET(_other_HEADERS Qtx.h QtxEvalExpr.h QtxMap.h + QtxMsgHandler.h QtxPreferenceMgr.h QtxResourceMgr.h QtxTranslator.h @@ -152,6 +153,7 @@ SET(_other_SOURCES QtxMRUAction.cxx QtxMainWindow.cxx QtxMenu.cxx + QtxMsgHandler.cxx QtxMultiAction.cxx QtxNotify.cxx QtxPagePrefMgr.cxx diff --git a/src/Qtx/QtxMsgHandler.cxx b/src/Qtx/QtxMsgHandler.cxx new file mode 100644 index 000000000..347165c04 --- /dev/null +++ b/src/Qtx/QtxMsgHandler.cxx @@ -0,0 +1,119 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "QtxMsgHandler.h" + +/*! + \brief Custom Qt messages handler. + + To install message handler use qInstallMessageHandler() function: + + \code + #include + qInstallMessageHandler(QtxMsgHandler); + \code + + To process Qt message implement a callback class by inheriting from + QtxMsgHandlerCallback and override its qtMessage() function. + + \sa QtxMsgHandlerCallback +*/ +void QtxMsgHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) +{ + foreach(QtxMsgHandlerCallback* callback, QtxMsgHandlerCallback::callbacks) + { + callback->qtMessage( type, context, message ); + } +} + +/*! + \class QtxMsgHandlerCallback + \brief A callback object to handle Qt messages. + + The QtxMsgHandlerCallback class works in conjunction with QtxMsgHandler() + function which is a message handler itself. + + Implement your own callback class by inheriting from QtxMsgHandlerCallback + and override its qtMessage() function. Default implementation does nothing. + + \sa QtxMsgHandler() +*/ + +QList QtxMsgHandlerCallback::callbacks; + +/*! + \brief Create new callback instance and activate it \a on is \c true. + \param on Automatically activate callback on creation. Defaults to \c true. + \sa activate() +*/ +QtxMsgHandlerCallback::QtxMsgHandlerCallback(bool on) +{ + if ( on ) + activate(); +} + +/*! + \brief Deactivate and destroy callback instance. + \sa deactivate() +*/ +QtxMsgHandlerCallback::~QtxMsgHandlerCallback() +{ + deactivate(); +} + +/*! + \brief Activate this callback instance in the message handler. + \sa deactivate() +*/ +void QtxMsgHandlerCallback::activate() +{ + if ( !callbacks.contains( this ) ) + callbacks.push_back( this ); +} + +/*! + \brief Deactivate this callback instance from the message handler. + \sa activate() +*/ +void QtxMsgHandlerCallback::deactivate() +{ + if ( callbacks.contains( this ) ) + callbacks.removeAll( this ); +} + +/*! + \brief This function is called when a new Qt message is reported. + + Override this method in your custom callback class to handle Qt + messages. + + Default implementation does nothing. + + \param type Qt message type. + \param context Message context. + \param message Message text. +*/ +void QtxMsgHandlerCallback::qtMessage(QtMsgType /*type*/, + const QMessageLogContext& /*context*/, + const QString& /*message*/) +{ +} diff --git a/src/Qtx/QtxMsgHandler.h b/src/Qtx/QtxMsgHandler.h new file mode 100644 index 000000000..a0836dea6 --- /dev/null +++ b/src/Qtx/QtxMsgHandler.h @@ -0,0 +1,49 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef QTXMSGHANDLER_H +#define QTXMSGHANDLER_H + +#include "Qtx.h" +#include + +void QTX_EXPORT QtxMsgHandler(QtMsgType, const QMessageLogContext&, const QString&); + +class QTX_EXPORT QtxMsgHandlerCallback +{ + friend void QtxMsgHandler(QtMsgType, const QMessageLogContext&, const QString&); + +public: + QtxMsgHandlerCallback(bool = true); + virtual ~QtxMsgHandlerCallback(); + +protected: + virtual void qtMessage(QtMsgType, const QMessageLogContext&, const QString&); + + void activate(); + void deactivate(); + +private: + static QList callbacks; +}; + +#endif // QTXMSGHANDLER_H diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 439a516e1..380ac23e8 100755 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -46,6 +46,7 @@ #include "Session_Session_i.hxx" #include +#include #include #ifdef USE_SALOME_STYLE @@ -95,27 +96,36 @@ * - stop Session ( must be idle ) * - get session state */ -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) -void MessageOutput( QtMsgType type, const char* msg ) -#else -void MessageOutput( QtMsgType type, const QMessageLogContext &context, const QString &msg ) -#endif + +class SessionMsgHandler: public QtxMsgHandlerCallback { - switch ( type ) +public: + SessionMsgHandler() {} + void qtMessage(QtMsgType type, const QMessageLogContext& context, const QString& message) { - case QtDebugMsg: + switch ( type ) + { + case QtDebugMsg: #ifdef QT_DEBUG_MESSAGE - MESSAGE( "Debug: " << qPrintable( QString(msg) ) ); + MESSAGE( "Debug: " << qPrintable( message ) ); #endif - break; - case QtWarningMsg: - MESSAGE( "Warning: " << qPrintable( QString(msg) ) ); - break; - case QtFatalMsg: - MESSAGE( "Fatal: " << qPrintable( QString(msg) ) ); - break; + break; + case QtWarningMsg: + MESSAGE( "Warning: " << qPrintable( message ) ); + break; + case QtCriticalMsg: + MESSAGE( "Critical: " << qPrintable( message ) ); + break; + case QtFatalMsg: + MESSAGE( "Fatal: " << qPrintable( message ) ); + break; + case QtInfoMsg: + default: + MESSAGE( "Information: " << qPrintable( message ) ); + break; + } } -} +}; QString salomeVersion() { @@ -332,11 +342,8 @@ void shutdownServers( SALOME_NamingService* theNS ) int main( int argc, char **argv ) { // Install Qt debug messages handler -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - qInstallMsgHandler( MessageOutput ); -#else - qInstallMessageHandler( MessageOutput ); -#endif + SessionMsgHandler msgHandler; + qInstallMessageHandler(QtxMsgHandler); // TODO (QT5 PORTING) Below is a temporary solution, to allow compiling with Qt 5 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)