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