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 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#include <string>
21
22#include <common.h>
23#include <core/profile.h>
24
25#include <wx/cmdline.h>
26
28
31#include <pcbnew/board.h>
36
37#include <string_utils.h>
38
41
42#include <reporter.h>
44
45#include <project.h>
48#include <pgm_base.h>
49
50#include <kiway.h>
51#include <kiface_ids.h>
52
53#include "drc_proto.h"
54
55PROJECT_CONTEXT loadKicadProject( const wxString& filename, std::optional<wxString> rulesFilePath )
56{
58
59 auto &manager = Pgm().GetSettingsManager();
60
61 wxFileName pro( filename );
62 wxFileName brdName ( filename );
63 wxFileName schName ( filename );
64 wxFileName ruleFileName ( filename );
65
67 brdName.SetExt( FILEEXT::KiCadPcbFileExtension );
69 ruleFileName.SetExt( FILEEXT::DesignRulesFileExtension );
70
71 brdName.MakeAbsolute();
72 schName.MakeAbsolute();
73 ruleFileName.MakeAbsolute();
74 pro.MakeAbsolute();
75
76 manager.LoadProject( pro.GetFullPath() );
77
78 rv.project = &manager.Prj();
80 std::string( brdName.GetFullPath().ToUTF8() ) ).release() );
81 rv.board->SetProject( rv.project );
82
83 if( rulesFilePath )
84 rv.rulesFilePath = *rulesFilePath;
85 else
86 rv.rulesFilePath = ruleFileName.GetFullPath();
87
88 if( wxFileExists( schName.GetFullPath() ) )
89 {
90 //printf("Generating SCH netlist for '%s'\n", (const char*) schName.GetFullPath() );
91 //rv.netlist.reset( new NETLIST );
92 //generateSchematicNetlist( schName.GetFullPath(), *rv.netlist.get() );
93 }
94
95 return rv;
96}
97
98
99int runDRCProto( PROJECT_CONTEXT project, std::shared_ptr<KIGFX::VIEW_OVERLAY> aDebugOverlay )
100{
101 std::shared_ptr<DRC_ENGINE> drcEngine( new DRC_ENGINE );
102
103 CONSOLE_LOG consoleLog;
104
105 project.board->GetDesignSettings().m_DRCEngine = drcEngine;
106
107 drcEngine->SetBoard( project.board.get() );
108 drcEngine->SetDesignSettings( &project.board->GetDesignSettings() );
109 drcEngine->SetLogReporter( new CONSOLE_MSG_REPORTER ( &consoleLog ) );
110 drcEngine->SetProgressReporter( new CONSOLE_PROGRESS_REPORTER ( &consoleLog ) );
111
112 drcEngine->SetViolationHandler(
113 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
114 const std::function<void( PCB_MARKER* )>& aPathGenerator )
115 {
116 // fixme
117 } );
118
119
120 drcEngine->InitEngine( project.rulesFilePath );
121 drcEngine->SetDebugOverlay( aDebugOverlay );
122
123 for( auto provider : drcEngine->GetTestProviders() )
124 {
125 //if( provider->GetName() == "diff_pair_coupling" )
126 // provider->Enable(true);
127 //else
128 // provider->Enable(false);
129 }
130
131 try
132 {
133 drcEngine->RunTests( EDA_UNITS::MM, true, false );
134 }
135 catch( const Clipper2Lib::Clipper2Exception& e )
136 {
137 consoleLog.Print( wxString::Format( "Clipper exception %s occurred.", e.what() ) );
138 }
139
140 return 0;
141}
General utilities for PCB file IO for QA programs.
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
Definition board.cpp:211
void Print(const wxString &aMessage)
Definition console_log.h:54
Design Rule Checker object that performs all the DRC tests.
Definition drc_engine.h:129
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
The common library.
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)
Definition drc_proto.cpp:99
static const std::string ProjectFileExtension
static const std::string KiCadSchematicFileExtension
static const std::string DesignRulesFileExtension
static const std::string KiCadPcbFileExtension
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.
see class PGM_BASE
std::shared_ptr< BOARD > board
Definition drc_proto.h:165
PROJECT * project
Definition drc_proto.h:163
wxString rulesFilePath
Definition drc_proto.h:164
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
Definition of file extensions used in Kicad.