Salome HOME
Copyright update: 2016
[modules/gui.git] / src / PVViewer / PVViewer_LogWindowAdapter.cxx
1 // Copyright (C) 2014-2016  CEA/DEN, EDF R&D, OPEN CASCADE
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, or (at your option) any later version.
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 "PVViewer_LogWindowAdapter.h"
21
22 #include <vtkObjectFactory.h>
23
24 #include <LogWindow.h>
25 #include <LogWindow.h>
26 #include <SUIT_Session.h>
27 #include <SALOME_Event.h>
28
29 vtkStandardNewMacro(PVViewer_LogWindowAdapter);
30
31 /*!
32  * Put the message in the log window. 
33  */
34 class TEvent: public SALOME_Event {
35   LogWindow* myWindow;
36   QString    myMsg;
37   QColor     myColor;
38   int        myFlags;
39   public:
40   TEvent( LogWindow* theWindow,  const QString theMsg, const QColor theColor, const int flags) :
41     myWindow ( theWindow ),
42     myMsg ( theMsg ),
43     myColor ( theColor ),
44     myFlags (flags)
45   {}
46
47   virtual void Execute() {
48     if(myWindow)
49       myWindow->putMessage(myMsg, myColor, myFlags);
50   }
51 };
52
53
54 PVViewer_LogWindowAdapter::PVViewer_LogWindowAdapter() :
55   TextCount(0),
56   ErrorCount(0),
57   WarningCount(0),
58   GenericWarningCount(0),
59   logWindow(0)
60 {
61 }
62
63 PVViewer_LogWindowAdapter::~PVViewer_LogWindowAdapter()
64 {
65 }
66
67 const unsigned int PVViewer_LogWindowAdapter::getTextCount()
68 {
69   return this->TextCount;
70 }
71
72 const unsigned int PVViewer_LogWindowAdapter::getErrorCount()
73 {
74   return this->ErrorCount;
75 }
76
77 const unsigned int PVViewer_LogWindowAdapter::getWarningCount()
78 {
79   return this->WarningCount;
80 }
81
82 const unsigned int PVViewer_LogWindowAdapter::getGenericWarningCount()
83 {
84   return this->GenericWarningCount;
85 }
86
87 void PVViewer_LogWindowAdapter::DisplayText(const char* text)
88 {
89   ++this->TextCount;
90   ProcessVoidEvent( new TEvent( getLogWindow(), text, Qt::darkGreen, LogWindow::DisplayNormal ));
91 }
92
93 void PVViewer_LogWindowAdapter::DisplayErrorText(const char* text)
94 {
95   ++this->ErrorCount;
96   ProcessVoidEvent( new TEvent( getLogWindow(), text, Qt::darkRed, LogWindow::DisplayNormal ));
97 }
98
99 void PVViewer_LogWindowAdapter::DisplayWarningText(const char* text)
100 {
101   ++this->WarningCount;
102   ProcessVoidEvent( new TEvent( getLogWindow(), text, Qt::black, LogWindow::DisplayNormal ));
103 }
104
105 void PVViewer_LogWindowAdapter::DisplayGenericWarningText(const char* text)
106 {
107   ++this->GenericWarningCount;
108   ProcessVoidEvent( new TEvent( getLogWindow() , text, Qt::black, LogWindow::DisplayNormal ));
109 }