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