KiCad PCB EDA Suite
drc_proto.h File Reference
#include <string>
#include <widgets/progress_reporter_base.h>
#include <reporter.h>
#include <core/optional.h>
#include <netlist_reader/pcb_netlist.h>
#include <netlist_reader/netlist_reader.h>

Go to the source code of this file.

Classes

class  CONSOLE_LOG
 
class  CONSOLE_PROGRESS_REPORTER
 
class  CONSOLE_MSG_REPORTER
 
struct  PROJECT_CONTEXT
 

Functions

PROJECT_CONTEXT loadKicadProject (const wxString &filename, OPT< wxString > rulesFilePath)
 
int runDRCProto (PROJECT_CONTEXT project, std::shared_ptr< KIGFX::VIEW_OVERLAY > aDebugOverlay=nullptr)
 

Function Documentation

◆ loadKicadProject()

PROJECT_CONTEXT loadKicadProject ( const wxString &  filename,
OPT< wxString >  rulesFilePath 
)

Definition at line 59 of file drc_proto.cpp.

60 {
61  PROJECT_CONTEXT rv;
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 }
std::shared_ptr< BOARD > board
Definition: drc_proto.h:168
const std::string ProjectFileExtension
wxString rulesFilePath
Definition: drc_proto.h:167
const std::string DesignRulesFileExtension
const std::string KiCadPcbFileExtension
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
PROJECT * project
Definition: drc_proto.h:166
const std::string KiCadSchematicFileExtension
std::unique_ptr< BOARD > ReadBoardFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
Read a board from a file, or another stream, as appropriate.

References PROJECT_CONTEXT::board, DesignRulesFileExtension, KiCadPcbFileExtension, KiCadSchematicFileExtension, Pgm(), PROJECT_CONTEXT::project, ProjectFileExtension, KI_TEST::ReadBoardFromFileOrStream(), and PROJECT_CONTEXT::rulesFilePath.

Referenced by main().

◆ runDRCProto()

int runDRCProto ( PROJECT_CONTEXT  project,
std::shared_ptr< KIGFX::VIEW_OVERLAY aDebugOverlay = nullptr 
)

Definition at line 103 of file drc_proto.cpp.

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, wxPoint aPos )
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 }
Design Rule Checker object that performs all the DRC tests.
Definition: drc_engine.h:81
void Print(const wxString &aMessage)
Definition: drc_proto.h:60
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

References Format(), MILLIMETRES, CONSOLE_LOG::Print(), and project.

Referenced by main().