KiCad PCB EDA Suite
drc_proto.cpp
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 #include <string>
25 
26 #include <common.h>
27 #include <profile.h>
28 
29 #include <wx/cmdline.h>
30 
31 #include <property_mgr.h>
32 
34 #include <pcbnew/drc/drc_engine.h>
35 #include <pcbnew/board.h>
39 
40 #include <kicad_string.h>
41 
44 
45 #include <reporter.h>
47 
48 #include <project.h>
51 #include <pgm_base.h>
52 
53 #include <kiway.h>
54 #include <kiface_ids.h>
55 
56 #include "drc_proto.h"
57 
58 PROJECT_CONTEXT loadKicadProject( wxString filename, OPT<wxString> rulesFilePath )
59 {
60  PROJECT_CONTEXT rv;
61 
62  auto &manager = Pgm().GetSettingsManager();
63 
64  wxFileName pro( filename );
65  wxFileName brdName ( filename );
66  wxFileName schName ( filename );
67  wxFileName ruleFileName ( filename );
68 
69  pro.SetExt( ProjectFileExtension );
70  brdName.SetExt( KiCadPcbFileExtension );
71  schName.SetExt( KiCadSchematicFileExtension );
72  ruleFileName.SetExt( DesignRulesFileExtension );
73 
74 
75 
76  brdName.MakeAbsolute();
77  schName.MakeAbsolute();
78  ruleFileName.MakeAbsolute();
79  pro.MakeAbsolute();
80 
81  manager.LoadProject( pro.GetFullPath() );
82 
83  rv.project = &manager.Prj();
85  std::string( brdName.GetFullPath().ToUTF8() ) ).release() );
86  rv.board->SetProject( rv.project );
87 
88  if( rulesFilePath )
89  rv.rulesFilePath = *rulesFilePath;
90  else
91  rv.rulesFilePath = ruleFileName.GetFullPath();
92 
93 
94  if( wxFileExists( schName.GetFullPath() ) )
95  {
96  //printf("Generating SCH netlist for '%s'\n", (const char*) schName.GetFullPath() );
97  //rv.netlist.reset( new NETLIST );
98  //generateSchematicNetlist( schName.GetFullPath(), *rv.netlist.get() );
99  }
100 
101  return rv;
102 }
103 
104 
105 int runDRCProto( PROJECT_CONTEXT project, std::shared_ptr<KIGFX::VIEW_OVERLAY> aDebugOverlay )
106 {
107  std::shared_ptr<DRC_ENGINE> drcEngine( new DRC_ENGINE );
108 
109  CONSOLE_LOG consoleLog;
110 
111  project.board->GetDesignSettings().m_DRCEngine = drcEngine;
112 
113  drcEngine->SetBoard( project.board.get() );
114  drcEngine->SetDesignSettings( &project.board->GetDesignSettings() );
115  drcEngine->SetLogReporter( new CONSOLE_MSG_REPORTER ( &consoleLog ) );
116  drcEngine->SetProgressReporter( new CONSOLE_PROGRESS_REPORTER ( &consoleLog ) );
117 
118  drcEngine->SetViolationHandler(
119  [&]( const std::shared_ptr<DRC_ITEM>& aItem, wxPoint aPos )
120  {
121  // fixme
122  } );
123 
124 
125  drcEngine->InitEngine( project.rulesFilePath );
126  drcEngine->SetDebugOverlay( aDebugOverlay );
127 
128  for( auto provider : drcEngine->GetTestProviders() )
129  {
130  //if( provider->GetName() == "diff_pair_coupling" )
131  // provider->Enable(true);
132  //else
133  // provider->Enable(false);
134  }
135 
136  try
137  {
138  drcEngine->RunTests( EDA_UNITS::MILLIMETRES, true, false );
139  }
140  catch( const ClipperLib::clipperException& e )
141  {
142  consoleLog.Print( wxString::Format( "Clipper exception %s occurred.", e.what() ) );
143  }
144 
145  return 0;
146 }
Design Rule Checker object that performs all the DRC tests.
Definition: drc_engine.h:80
std::shared_ptr< BOARD > board
Definition: drc_proto.h:163
const std::string ProjectFileExtension
wxString rulesFilePath
Definition: drc_proto.h:162
const std::string DesignRulesFileExtension
const std::string KiCadPcbFileExtension
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
void Print(const wxString &aMessage)
Definition: drc_proto.h:60
Definition of file extensions used in Kicad.
PROJECT * project
Definition: drc_proto.h:161
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
see class PGM_BASE
int runDRCProto(PROJECT_CONTEXT project, std::shared_ptr< KIGFX::VIEW_OVERLAY > aDebugOverlay)
Definition: drc_proto.cpp:105
const std::string KiCadSchematicFileExtension
The common library.
boost::optional< T > OPT
Definition: optional.h:7
General utilities for PCB file IO for QA programs.
std::unique_ptr< BOARD > ReadBoardFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
Read a board from a file, or another stream, as appropriate.
PROJECT_CONTEXT loadKicadProject(wxString filename, OPT< wxString > rulesFilePath)
Definition: drc_proto.cpp:58