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-2020 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:
101  PROGRESS_REPORTER( 0 ),
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%%", m_rptMessage, (double) m_progress / (double) m_maxProgress * 100.0 ) );
116  return true;
117  }
118 
120 };
121 
123 {
124 public:
126  m_log(log)
127  {};
129 
130 
131  virtual REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override
132  {
133  switch( aSeverity )
134  {
135  case RPT_SEVERITY_ERROR:
137  m_log->Print("ERROR | ");
138  break;
139 
140  default:
142  m_log->Print(" | ");
143  }
144 
146  m_log->Print( aText + "\n" );
147  return *this;
148  }
149 
150  virtual bool HasMessage() const override
151  {
152  return true;
153  }
154 
155 private:
157 };
158 
159 
162  wxString rulesFilePath;
163  std::shared_ptr<BOARD> board;
164  std::shared_ptr<NETLIST> netlist;
165 };
166 
167 PROJECT_CONTEXT loadKicadProject( wxString filename, OPT<wxString> rulesFilePath );
168 int runDRCProto( PROJECT_CONTEXT project, std::shared_ptr<KIGFX::VIEW_OVERLAY> aDebugOverlay = nullptr);
169 
170 #endif
171 
172 
Container for project specific data.
Definition: project.h:62
std::shared_ptr< BOARD > board
Definition: drc_proto.h:163
SEVERITY
Definition: ui_common.h:83
CONSOLE_LOG * m_log
Definition: drc_proto.h:156
A progress reporter for use in multi-threaded environments.
wxString rulesFilePath
Definition: drc_proto.h:162
CONSOLE_MSG_REPORTER(CONSOLE_LOG *log)
Definition: drc_proto.h:125
std::atomic_int m_progress
int color
Definition: DXF_plotter.cpp:60
std::mutex m_lock
Definition: drc_proto.h:94
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
virtual void SetCurrentProgress(double aProgress) override
Set the progress value to aProgress (0..1)
Definition: drc_proto.h:105
void Print(const wxString &aMessage)
Definition: drc_proto.h:60
virtual void SetCurrentProgress(double aProgress)
Set the progress value to aProgress (0..1)
virtual bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: drc_proto.h:150
PROJECT_CONTEXT loadKicadProject(wxString filename, OPT< wxString > rulesFilePath)
Definition: drc_proto.cpp:58
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: drc_proto.h:131
int runDRCProto(PROJECT_CONTEXT project, std::shared_ptr< KIGFX::VIEW_OVERLAY > aDebugOverlay=nullptr)
Definition: drc_proto.cpp:105
void SetColor(COLOR color)
Definition: drc_proto.h:72
virtual bool updateUI() override
Definition: drc_proto.h:112
PROJECT * project
Definition: drc_proto.h:161
void PrintProgress(const wxString &aMessage)
Definition: drc_proto.h:48
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
std::atomic_int m_maxProgress
bool m_lastLineIsProgressBar
Definition: drc_proto.h:93
std::shared_ptr< NETLIST > netlist
Definition: drc_proto.h:164
CONSOLE_PROGRESS_REPORTER(CONSOLE_LOG *log)
Definition: drc_proto.h:100