KiCad PCB EDA Suite
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 <core/optional.h>
34 
35 class BOARD;
36 
38 {
39 public:
40  enum COLOR {
41  RED = 0,
44  };
45 
47 
48  void PrintProgress( const wxString& aMessage )
49  {
51  eraseLastLine();
52 
53  printf("%s", (const char *) aMessage.c_str() );
54  fflush(stdout);
55 
57  }
58 
59 
60  void Print( const wxString& aMessage )
61  {
63  eraseLastLine();
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 
86 private:
88  {
89  printf("\r\033[K");
90  fflush(stdout);
91  }
92 
94  std::mutex m_lock;
95 };
96 
98 {
99 public:
102  m_log( log ) {};
104 
105  virtual void SetCurrentProgress( double aProgress ) override
106  {
108  updateUI();
109  }
110 
111 private:
112  virtual bool updateUI() override
113  {
115  m_log->PrintProgress( wxString::Format( " | %s : %.02f%%",
116  m_rptMessage,
117  (double) m_progress / (double) m_maxProgress *
118  100.0 ) );
119  return true;
120  }
121 
123 };
124 
126 {
127 public:
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  {
139  case RPT_SEVERITY_ERROR:
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 
159 private:
161 };
162 
163 
165 {
167  wxString rulesFilePath;
168  std::shared_ptr<BOARD> board;
169  std::shared_ptr<NETLIST> netlist;
170 };
171 
172 PROJECT_CONTEXT loadKicadProject( const wxString& filename, OPT<wxString> rulesFilePath );
173 
174 int runDRCProto( PROJECT_CONTEXT project,
175  std::shared_ptr<KIGFX::VIEW_OVERLAY> aDebugOverlay = nullptr );
176 
177 #endif
178 
179 
Container for project specific data.
Definition: project.h:62
std::shared_ptr< BOARD > board
Definition: drc_proto.h:168
CONSOLE_LOG * m_log
Definition: drc_proto.h:160
wxString rulesFilePath
Definition: drc_proto.h:167
CONSOLE_MSG_REPORTER(CONSOLE_LOG *log)
Definition: drc_proto.h:128
int color
Definition: DXF_plotter.cpp:57
std::mutex m_lock
Definition: drc_proto.h:94
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:70
virtual void SetCurrentProgress(double aProgress) override
Set the progress value to aProgress (0..1).
Definition: drc_proto.h:105
PROJECT_CONTEXT loadKicadProject(const wxString &filename, OPT< wxString > rulesFilePath)
Definition: drc_proto.cpp:59
void Print(const wxString &aMessage)
Definition: drc_proto.h:60
virtual bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: drc_proto.h:154
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: drc_proto.h:134
int runDRCProto(PROJECT_CONTEXT project, std::shared_ptr< KIGFX::VIEW_OVERLAY > aDebugOverlay=nullptr)
Definition: drc_proto.cpp:103
void SetColor(COLOR color)
Definition: drc_proto.h:72
virtual bool updateUI() override
Definition: drc_proto.h:112
SEVERITY
PROJECT * project
Definition: drc_proto.h:166
void PrintProgress(const wxString &aMessage)
Definition: drc_proto.h:48
This implements all the tricky bits for thread safety, but the GUI is left to derived classes.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
void eraseLastLine()
Definition: drc_proto.h:87
boost::optional< T > OPT
Definition: optional.h:7
bool m_lastLineIsProgressBar
Definition: drc_proto.h:93
std::shared_ptr< NETLIST > netlist
Definition: drc_proto.h:169
CONSOLE_PROGRESS_REPORTER(CONSOLE_LOG *log)
Definition: drc_proto.h:100
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).