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 The 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>
33#include <netlist_reader/netlist_reader.h>
34#include <view/view_overlay.h>
35
36class BOARD;
37
38class CONSOLE_LOG
39{
40public:
41 enum COLOR {
42 RED = 0,
43 GREEN,
45 };
46
48
49 void PrintProgress( const wxString& aMessage )
50 {
53
54 printf("%s", (const char *) aMessage.c_str() );
55 fflush(stdout);
56
58 }
59
60
61 void Print( const wxString& aMessage )
62 {
65
66 printf("%s", (const char *) aMessage.c_str() );
67 fflush(stdout);
68
70 }
71
72
73 void SetColor( COLOR color )
74 {
75 std::map<COLOR, wxString> colorMap =
76 {
77 { RED, "\033[0;31m" },
78 { GREEN, "\033[0;32m" },
79 { DEFAULT, "\033[0;37m" }
80 };
81
82 printf( "%s", (const char*) colorMap[ color ].c_str() );
83 fflush(stdout);
84 }
85
86
87private:
89 {
90 printf("\r\033[K");
91 fflush(stdout);
92 }
93
94 bool m_lastLineIsProgressBar = false;
95 std::mutex m_lock;
96};
97
99{
100public:
105
106 virtual void SetCurrentProgress( double aProgress ) override
107 {
109 updateUI();
110 }
111
112private:
113 virtual bool updateUI() override
114 {
115 m_log->SetColor( CONSOLE_LOG::GREEN );
116 m_log->PrintProgress( wxString::Format( " | %s : %.02f%%",
118 (double) m_progress / (double) m_maxProgress *
119 100.0 ) );
120 return true;
121 }
122
124};
125
126class CONSOLE_MSG_REPORTER : public REPORTER
127{
128public:
130 m_log(log)
131 {};
133
134
135 virtual REPORTER& Report( const wxString& aText,
136 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override
137 {
138 switch( aSeverity )
139 {
141 m_log->SetColor( CONSOLE_LOG::RED );
142 m_log->Print("ERROR | ");
143 break;
144
145 default:
146 m_log->SetColor( CONSOLE_LOG::DEFAULT );
147 m_log->Print(" | ");
148 }
149
150 m_log->SetColor( CONSOLE_LOG::DEFAULT );
151 m_log->Print( aText + "\n" );
152 return *this;
153 }
154
155 virtual bool HasMessage() const override
156 {
157 return true;
158 }
159
160private:
162};
163
164
166{
169 std::shared_ptr<BOARD> board;
170 std::shared_ptr<NETLIST> netlist;
171};
172
173PROJECT_CONTEXT loadKicadProject( const wxString& filename, std::optional<wxString> rulesFilePath );
174
176 std::shared_ptr<KIGFX::VIEW_OVERLAY> aDebugOverlay = nullptr );
177
178#endif
179
180
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
void Print(const wxString &aMessage)
Definition drc_proto.h:61
void PrintProgress(const wxString &aMessage)
Definition drc_proto.h:49
std::mutex m_lock
Definition console_log.h:92
void SetColor(COLOR color)
Definition drc_proto.h:73
void eraseLastLine()
Definition console_log.h:85
bool m_lastLineIsProgressBar
Definition console_log.h:91
CONSOLE_LOG * m_log
virtual bool HasMessage() const override
Returns true if any messages were reported.
Definition drc_proto.h:155
CONSOLE_MSG_REPORTER(CONSOLE_LOG *log)
Definition drc_proto.h:129
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition drc_proto.h:135
virtual void SetCurrentProgress(double aProgress) override
Set the progress value to aProgress (0..1).
Definition drc_proto.h:106
CONSOLE_PROGRESS_REPORTER(CONSOLE_LOG *log)
Definition drc_proto.h:101
virtual bool updateUI() override
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:65
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
REPORTER()
Definition reporter.h:75
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)
SEVERITY
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_UNDEFINED
std::shared_ptr< BOARD > board
Definition drc_proto.h:169
PROJECT * project
Definition drc_proto.h:167
wxString rulesFilePath
Definition drc_proto.h:168
std::shared_ptr< NETLIST > netlist
Definition drc_proto.h:170