KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_proto.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>
34
35class BOARD;
36
37class CONSOLE_LOG
38{
39public:
40 enum COLOR {
41 RED = 0,
42 GREEN,
44 };
45
47
48 void PrintProgress( const wxString& aMessage )
49 {
52
53 printf("%s", (const char *) aMessage.c_str() );
54 fflush(stdout);
55
57 }
58
59
60 void Print( const wxString& aMessage )
61 {
64
65 printf("%s", (const char *) aMessage.c_str() );
66 fflush(stdout);
67
69 }
70
71
73 {
74 std::map<COLOR, wxString> colorMap =
75 {
76 { RED, "\033[0;31m" },
77 { GREEN, "\033[0;32m" },
78 { DEFAULT, "\033[0;37m" }
79 };
80
81 printf( "%s", (const char*) colorMap[ color ].c_str() );
82 fflush(stdout);
83 }
84
85
86private:
88 {
89 printf("\r\033[K");
90 fflush(stdout);
91 }
92
93 bool m_lastLineIsProgressBar = false;
94 std::mutex m_lock;
95};
96
98{
99public:
102 m_log( log ) {};
104
105 virtual void SetCurrentProgress( double aProgress ) override
106 {
108 updateUI();
109 }
110
111private:
112 virtual bool updateUI() override
113 {
115 m_log->PrintProgress( wxString::Format( " | %s : %.02f%%",
117 (double) m_progress / (double) m_maxProgress *
118 100.0 ) );
119 return true;
120 }
121
123};
124
125class CONSOLE_MSG_REPORTER : public REPORTER
126{
127public:
129 m_log(log)
130 {};
132
133
134 virtual REPORTER& Report( const wxString& aText,
135 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override
136 {
137 switch( aSeverity )
138 {
141 m_log->Print("ERROR | ");
142 break;
143
144 default:
146 m_log->Print(" | ");
147 }
148
150 m_log->Print( aText + "\n" );
151 return *this;
152 }
153
154 virtual bool HasMessage() const override
155 {
156 return true;
157 }
158
159private:
161};
162
163
165{
168 std::shared_ptr<BOARD> board;
169 std::shared_ptr<NETLIST> netlist;
170};
171
172PROJECT_CONTEXT loadKicadProject( const wxString& filename, std::optional<wxString> rulesFilePath );
173
175 std::shared_ptr<KIGFX::VIEW_OVERLAY> aDebugOverlay = nullptr );
176
177#endif
178
179
int color
Definition: DXF_plotter.cpp:58
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:281
void Print(const wxString &aMessage)
Definition: drc_proto.h:60
void PrintProgress(const wxString &aMessage)
Definition: drc_proto.h:48
std::mutex m_lock
Definition: console_log.h:92
void SetColor(COLOR color)
Definition: drc_proto.h:72
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: drc_proto.h:154
CONSOLE_MSG_REPORTER(CONSOLE_LOG *log)
Definition: drc_proto.h:128
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: drc_proto.h:134
virtual void SetCurrentProgress(double aProgress) override
Set the progress value to aProgress (0..1).
Definition: drc_proto.h:105
CONSOLE_PROGRESS_REPORTER(CONSOLE_LOG *log)
Definition: drc_proto.h:100
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).
Container for project specific data.
Definition: project.h:62
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
PROJECT_CONTEXT loadKicadProject(const wxString &filename, std::optional< wxString > rulesFilePath)
Definition: drc_proto.cpp:59
int runDRCProto(PROJECT_CONTEXT project, std::shared_ptr< KIGFX::VIEW_OVERLAY > aDebugOverlay=nullptr)
Definition: drc_proto.cpp:103
SEVERITY
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_UNDEFINED
std::shared_ptr< BOARD > board
Definition: drc_proto.h:168
PROJECT * project
Definition: drc_proto.h:166
wxString rulesFilePath
Definition: drc_proto.h:167
std::shared_ptr< NETLIST > netlist
Definition: drc_proto.h:169