KiCad PCB EDA Suite
Loading...
Searching...
No Matches
console_log.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef __DRC_PROTO_H
25#define __DRC_PROTO_H
26
27#include <string>
28
30#include <reporter.h>
31#include <optional>
32
33class BOARD;
34
36{
37public:
38 enum COLOR {
39 RED = 0,
42 };
43
45
46 void PrintProgress( const wxString& aMessage )
47 {
50
51 printf("%s", (const char *) aMessage.c_str() );
52 fflush(stdout);
53
55 }
56
57
58 void Print( const wxString& aMessage )
59 {
62
63 printf("%s", (const char *) aMessage.c_str() );
64 fflush(stdout);
65
67 }
68
69
71 {
72 std::map<COLOR, wxString> colorMap =
73 {
74 { RED, "\033[0;31m" },
75 { GREEN, "\033[0;32m" },
76 { DEFAULT, "\033[0;37m" }
77 };
78
79 printf( "%s", (const char*) colorMap[ color ].c_str() );
80 fflush(stdout);
81 }
82
83
84private:
86 {
87 printf("\r\033[K");
88 fflush(stdout);
89 }
90
92 std::mutex m_lock;
93};
94
96{
97public:
100 m_log( log ) {};
102
103 virtual void SetCurrentProgress( double aProgress ) override
104 {
106 updateUI();
107 }
108
109private:
110 virtual bool updateUI() override
111 {
113 m_log->PrintProgress( wxString::Format( " | %s : %.02f%%",
115 (double) m_progress / (double) m_maxProgress *
116 100.0 ) );
117 return true;
118 }
119
121};
122
124{
125public:
127 m_log(log)
128 {};
130
131
132 virtual REPORTER& Report( const wxString& aText,
133 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override
134 {
135 switch( aSeverity )
136 {
139 m_log->Print("ERROR | ");
140 break;
141
142 default:
144 m_log->Print(" | ");
145 }
146
148 m_log->Print( aText + "\n" );
149 return *this;
150 }
151
152 virtual bool HasMessage() const override
153 {
154 return true;
155 }
156
157private:
159};
160
161#endif
162
163
int color
Definition: DXF_plotter.cpp:58
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
void Print(const wxString &aMessage)
Definition: console_log.h:58
void PrintProgress(const wxString &aMessage)
Definition: console_log.h:46
std::mutex m_lock
Definition: console_log.h:92
void SetColor(COLOR color)
Definition: console_log.h:70
void eraseLastLine()
Definition: console_log.h:85
bool m_lastLineIsProgressBar
Definition: console_log.h:91
CONSOLE_LOG * m_log
Definition: console_log.h:158
virtual bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: console_log.h:152
CONSOLE_MSG_REPORTER(CONSOLE_LOG *log)
Definition: console_log.h:126
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: console_log.h:132
virtual void SetCurrentProgress(double aProgress) override
Set the progress value to aProgress (0..1).
Definition: console_log.h:103
CONSOLE_PROGRESS_REPORTER(CONSOLE_LOG *log)
Definition: console_log.h:98
virtual bool updateUI() override
Definition: console_log.h:110
This implements all the tricky bits for thread safety, but the GUI is left to derived classes.
virtual void SetCurrentProgress(double aProgress) override
Set the progress value to aProgress (0..1).
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
SEVERITY
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_UNDEFINED