Salome HOME
8ab4d009eb33129b3c7214adb6a6c75fdcb09fdd
[modules/paravis.git] / src / PVGUI / PVGUI_OutputWindowAdapter.cxx
1 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "PVGUI_OutputWindowAdapter.h"
21
22 #include <vtkObjectFactory.h>
23
24 #include <LightApp_Application.h>
25 #include <LogWindow.h>
26 #include <SUIT_Session.h>
27 #include <SALOME_Event.h>
28
29 vtkStandardNewMacro(PVGUI_OutputWindowAdapter);
30
31
32
33 /*!
34  * Put the message in the log window. 
35  */
36 class TEvent: public SALOME_Event {
37   LogWindow* myWindow;
38   QString    myMsg;
39   QColor     myColor;
40   int        myFlags;
41   public:
42   TEvent( LogWindow* theWindow,  const QString theMsg, const QColor theColor, const int flags) :
43     myWindow ( theWindow ),
44     myMsg ( theMsg ),
45     myColor ( theColor ),
46     myFlags (flags)
47   {}
48
49   virtual void Execute() {
50     if(myWindow)
51       myWindow->putMessage(myMsg, myColor, myFlags);
52   }
53 };
54
55
56 PVGUI_OutputWindowAdapter::PVGUI_OutputWindowAdapter() :
57   TextCount(0),
58   ErrorCount(0),
59   WarningCount(0),
60   GenericWarningCount(0)
61 {
62 }
63
64 PVGUI_OutputWindowAdapter::~PVGUI_OutputWindowAdapter()
65 {
66 }
67
68 const unsigned int PVGUI_OutputWindowAdapter::getTextCount()
69 {
70   return this->TextCount;
71 }
72
73 const unsigned int PVGUI_OutputWindowAdapter::getErrorCount()
74 {
75   return this->ErrorCount;
76 }
77
78 const unsigned int PVGUI_OutputWindowAdapter::getWarningCount()
79 {
80   return this->WarningCount;
81 }
82
83 const unsigned int PVGUI_OutputWindowAdapter::getGenericWarningCount()
84 {
85   return this->GenericWarningCount;
86 }
87
88 static LogWindow* getLogWindow()
89 {
90   LogWindow* wnd = 0;
91   LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
92   if ( anApp )
93     wnd = anApp->logWindow();
94   return wnd;
95 }
96
97 void PVGUI_OutputWindowAdapter::DisplayText(const char* text)
98 {
99   ++this->TextCount;
100   ProcessVoidEvent( new TEvent( getLogWindow(), text, Qt::darkGreen, LogWindow::DisplayNormal ));
101 }
102
103 void PVGUI_OutputWindowAdapter::DisplayErrorText(const char* text)
104 {
105   ++this->ErrorCount;
106   ProcessVoidEvent( new TEvent( getLogWindow(), text, Qt::darkRed, LogWindow::DisplayNormal ));
107 }
108
109 void PVGUI_OutputWindowAdapter::DisplayWarningText(const char* text)
110 {
111   ++this->WarningCount;
112   ProcessVoidEvent( new TEvent( getLogWindow(), text, Qt::black, LogWindow::DisplayNormal ));
113 }
114
115 void PVGUI_OutputWindowAdapter::DisplayGenericWarningText(const char* text)
116 {
117   ++this->GenericWarningCount;
118   ProcessVoidEvent( new TEvent( getLogWindow() , text, Qt::black, LogWindow::DisplayNormal ));
119 }