28#include <wx/filename.h>
30#include <wx/stdstream.h>
31#include <wx/wfstream.h>
50 std::vector<BOARD_CONNECTED_ITEM*> parents;
52 parents.resize( evt.
uuids.size() );
56 for(
int i = 0; i < evt.
uuids.size(); i++ )
58 if( item->m_Uuid == evt.
uuids[i] )
72 if ( parents.size() > 0 )
82 fgets( str,
sizeof( str ) - 1, f );
83 return wxString( str );
88 m_mode(
PNS::ROUTER_MODE::PNS_MODE_ROUTE_SINGLE )
96 const wxString type =
static_cast<wxString
>( aJSON.at(
"type" ).get<wxString>() );
98 if( type == wxT(
"segment") )
101 sh->SetSeg(
SEG( aJSON.at(
"start" ).get<
VECTOR2I>(), aJSON.at(
"end" ).get<
VECTOR2I>() ) );
102 sh->SetWidth( aJSON.at(
"width" ).get<
int>() );
105 else if( type == wxT(
"circle") )
108 sh->SetCenter( aJSON.at(
"center" ).get<
VECTOR2I>() );
109 sh->SetRadius( aJSON.at(
"radius" ).get<
int>() );
112 else if( type == wxT(
"arc") )
117 int width = aJSON.at(
"width" ).get<
int>();
119 std::shared_ptr<SHAPE_ARC> sh(
new SHAPE_ARC( start, mid,
end, width ) );
135 a.
x = wxAtoi( aTokens.GetNextToken() );
136 a.
y = wxAtoi( aTokens.GetNextToken() );
137 b.
x = wxAtoi( aTokens.GetNextToken() );
138 b.
y = wxAtoi( aTokens.GetNextToken() );
139 int width = wxAtoi( aTokens.GetNextToken() );
140 sh->SetSeg(
SEG( a, b ));
141 sh->SetWidth( width );
148 a.
x = wxAtoi( aTokens.GetNextToken() );
149 a.
y = wxAtoi( aTokens.GetNextToken() );
150 int radius = wxAtoi( aTokens.GetNextToken() );
160 wxStringTokenizer& aTokens )
162 if( cmd == wxS(
"net" ) )
164 aItem->
SetNet(
m_board->FindNet( wxAtoi( aTokens.GetNextToken() ) ) );
167 else if( cmd == wxS(
"layers" ) )
169 int start = wxAtoi( aTokens.GetNextToken() );
170 int end = wxAtoi( aTokens.GetNextToken() );
180 aItem->
SetNet(
m_board->FindNet( aJSON.at(
"net" ).get<wxString>() ) );
182 PNS_LAYER_RANGE( aJSON.at(
"layers" ).at( 0 ).get<
int>(), aJSON.at(
"layers" ).at( 1 ).get<
int>() ) );
189 std::unique_ptr<PNS::SEGMENT> seg(
new PNS::SEGMENT() );
191 while( aTokens.CountTokens() )
193 wxString cmd = aTokens.GetNextToken();
197 if( cmd == wxS(
"shape" ) )
217 while( aTokens.CountTokens() )
219 wxString cmd = aTokens.GetNextToken();
223 if( cmd == wxS(
"shape" ) )
235 else if( cmd == wxS(
"drill" ) )
237 via->SetDrill( wxAtoi( aTokens.GetNextToken() ) );
247 wxString kind = aJSON.at(
"kind").get<wxString>();
249 if( kind == wxT(
"segment") )
251 auto parsedShape =
parseShape( aJSON.at(
"shape") );
256 auto shape =
static_cast<const SHAPE_SEGMENT*
>( parsedShape.get() );
257 std::unique_ptr<PNS::SEGMENT> seg(
new PNS::SEGMENT( *shape,
nullptr ) );
259 return std::move( seg );
261 else if ( kind == wxT(
"arc" ) )
263 auto parsedShape =
parseShape( aJSON.at(
"shape") );
268 auto shape =
static_cast<const SHAPE_ARC*
>( parsedShape.get() );
269 std::unique_ptr<PNS::ARC> arc(
new PNS::ARC( *shape,
nullptr ) );
271 return std::move( arc );
273 else if ( kind == wxT(
"via" ) )
275 auto parsedShape =
parseShape( aJSON.at(
"shape") );
280 auto shape =
static_cast<const SHAPE_CIRCLE*
>( parsedShape.get() );
283 via->SetPos( shape->Centre() );
284 via->SetDiameter(
via->Layers().Start(), shape->GetRadius() * 2 );
285 via->SetDrill( aJSON.at(
"drill").get<
int>() );
286 return std::move(
via);
295 wxString type = aTokens.GetNextToken();
297 if( type == wxS(
"segment" ) )
299 else if( type == wxS(
"via" ) )
310 if( a->
Net() != b->
Net() )
328 if( va->
Pos() != vb->
Pos() )
337 if( sa->
Seg() != sb->
Seg() )
348const std::set<PNS::ITEM*>
deduplicate(
const std::vector<PNS::ITEM*>& items )
350 std::set<PNS::ITEM*> rv;
354 bool isDuplicate =
false;
397 chkAddedItems.erase( chk );
405 if( chkAddedItems.empty() && check.
m_removedIds.empty() )
426 wxFFileOutputStream fp( logFileName.GetFullPath(), wxT(
"wt" ) );
432 aRpt->
Report( wxString::Format( wxT(
"Failed to write log file: %s"), logFileName.GetFullPath() ),
RPT_SEVERITY_ERROR );
437 wxScopedCharBuffer utf8 = logString.ToUTF8();
438 fp.Write( utf8.data(), utf8.length() );
447 wxFileName fname_log( logFileName );
448 fname_log.SetExt( wxT(
"log" ) );
450 wxFileName fname_dump( logFileName );
451 fname_dump.SetExt( wxT(
"dump" ) );
453 if( !boardFileName.IsEmpty() )
455 fname_dump = boardFileName;
458 wxFileName fname_project( logFileName );
459 fname_project.SetExt( wxT(
"kicad_pro" ) );
460 fname_project.MakeAbsolute();
462 wxFileName fname_settings( logFileName );
463 fname_settings.SetExt( wxT(
"settings" ) );
465 aRpt->
Report( wxString::Format( wxT(
"Loading router settings from '%s'" ),
466 fname_settings.GetFullPath() ) );
468 bool ok =
m_routerSettings->LoadFromRawFile( fname_settings.GetFullPath() );
472 aRpt->
Report( wxT(
"Failed to load routing settings. Using defaults." ),
476 aRpt->
Report( wxString::Format( wxT(
"Loading project settings from '%s'" ),
477 fname_settings.GetFullPath() ) );
487 aRpt->
Report( wxString::Format( wxT(
"Loading board snapshot from '%s'"),
488 fname_dump.GetFullPath() ) );
490 m_board.reset( io.
LoadBoard( fname_dump.GetFullPath(),
nullptr,
nullptr ) );
493 std::shared_ptr<DRC_ENGINE> drcEngine(
new DRC_ENGINE );
500 m_board->SynchronizeNetsAndNetClasses(
true );
502 drcEngine->SetBoard(
m_board.get() );
503 drcEngine->SetDesignSettings( &bds );
504 drcEngine->SetLogReporter( aRpt );
505 drcEngine->InitEngine( wxFileName() );
509 aRpt->
Report( wxString::Format(
"parse error : %s (%s)\n",
511 parse_error.
What() ),
518 ok =
loadJsonLog( logFileName.GetFullPath(), aRpt,
false );
519 if( !ok && logFileName.FileExists() )
531 wxFFileInputStream fp( aFilename, wxT(
"rt" ) );
532 wxStdInputStream fstream( fp );
537 aRpt->
Report( wxString::Format(
"Loading log from: %s", aFilename ) );
550 nlohmann::json logJson = nlohmann::json::parse( fstream,
nullptr,
554 if( logJson.contains(
"board_hash") )
556 m_boardHash = logJson.at(
"board_hash").get<wxString>();
559 if( logJson.contains(
"test_case_type") )
569 for(
const nlohmann::json& event : logJson.at(
"events" ) )
574 for(
const nlohmann::json& addedItem : logJson.at(
"addedItems" ) )
580 for(
const nlohmann::json& addedItem : logJson.at(
"removedItems" ) )
587 aRpt->
Report( wxString::Format(
"JSON log load: %lu events, %lu added, %lu removed\n",
m_events.size(),
594 catch(
const std::exception& exc )
609 FILE* f = fopen( aFilename.c_str(),
"rb" );
611 aRpt->
Report( wxString::Format(
"Loading log from '%s'", aFilename ) );
624 wxStringTokenizer tokens( line );
626 if( !tokens.CountTokens() )
629 wxString cmd = tokens.GetNextToken();
631 if( cmd == wxT(
"mode" ) )
635 else if( cmd == wxT(
"event" ) )
639 else if( cmd == wxT(
"added" ) )
644 else if( cmd == wxT(
"removed" ) )
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
Container for design settings for a BOARD object.
std::shared_ptr< DRC_ENGINE > m_DRCEngine
bool m_UseConnectedTrackWidth
Design Rule Checker object that performs all the DRC tests.
virtual const wxString What() const
A composite of Problem() and Where()
virtual const wxString Problem() const
what was the problem?
A #PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
Base class for PNS router board items.
void SetLayers(const PNS_LAYER_RANGE &aLayers)
const PNS_LAYER_RANGE & Layers() const
virtual NET_HANDLE Net() const
PnsKind Kind() const
Return the type (kind) of the item.
void SetNet(NET_HANDLE aNet)
static wxString FormatLogFileAsJSON(const LOG_DATA &aLogData)
static EVENT_ENTRY ParseEventFromJSON(const nlohmann::json &aJSON)
static EVENT_ENTRY ParseEvent(const wxString &aLine)
Contain all persistent settings of the router, such as the mode, optimization effort,...
int Width() const override
int Diameter(int aLayer) const
const VECTOR2I & Pos() const
static constexpr int ALL_LAYERS
Represent a contiguous set of PCB layers.
bool parseCommonPnsProps(const nlohmann::json &aJSON, PNS::ITEM *aItem)
BOARD_CONNECTED_ITEM * ItemById(const PNS::LOGGER::EVENT_ENTRY &evt)
std::unique_ptr< PNS::VIA > parseLegacyPnsViaFromString(wxStringTokenizer &aTokens)
const std::optional< wxString > GetLogBoardHash(const wxString &logFileName)
bool SaveLog(const wxFileName &logFileName, REPORTER *aRpt)
bool loadLegacyLog(const wxString &aFilename, REPORTER *aRpt)
std::shared_ptr< BOARD > m_board
bool parseLegacyCommonPnsProps(PNS::ITEM *aItem, const wxString &cmd, wxStringTokenizer &aTokens)
std::shared_ptr< SETTINGS_MANAGER > m_settingsMgr
std::shared_ptr< SHAPE > parseShape(const nlohmann::json &aJSON)
std::unique_ptr< PNS::ITEM > parseItem(const nlohmann::json &aJSON)
std::shared_ptr< SHAPE > parseLegacyShape(SHAPE_TYPE expectedType, wxStringTokenizer &aTokens)
std::vector< std::unique_ptr< PNS::ITEM > > m_parsed_items
std::optional< wxString > m_boardHash
COMMIT_STATE m_commitState
bool loadJsonLog(const wxString &aFilename, REPORTER *aRpt, bool aHashOnly=false)
std::vector< PNS::LOGGER::EVENT_ENTRY > m_events
std::vector< BOARD_CONNECTED_ITEM * > ItemsById(const PNS::LOGGER::EVENT_ENTRY &evt)
std::unique_ptr< PNS::SEGMENT > parseLegacyPnsSegmentFromString(wxStringTokenizer &aTokens)
std::optional< PNS::LOGGER::TEST_CASE_TYPE > m_testCaseType
std::unique_ptr< PNS::ROUTING_SETTINGS > m_routerSettings
bool Load(const wxFileName &logFileName, REPORTER *aRpt, const wxString boardFileName=wxT(""))
std::unique_ptr< PNS::ITEM > parseLegacyItemFromString(wxStringTokenizer &aTokens)
Container for project specific data.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
const VECTOR2I GetCenter() const
Push and Shove diff pair dimensions (gap) settings dialog.
bool comparePnsItems(const PNS::ITEM *a, const PNS::ITEM *b)
static const wxString readLine(FILE *f)
const std::set< PNS::ITEM * > deduplicate(const std::vector< PNS::ITEM * > &items)
SHAPE_TYPE
Lists all supported shapes.
A filename or source description, a problem input line, a line number, a byte offset,...
std::vector< KIID > uuids
std::optional< wxString > m_BoardHash
std::optional< TEST_CASE_TYPE > m_TestCaseType
std::vector< ITEM * > m_AddedItems
std::vector< EVENT_ENTRY > m_Events
std::set< KIID > m_RemovedItems
std::vector< ITEM * > m_Heads
std::set< KIID > m_removedIds
bool Compare(const COMMIT_STATE &aOther)
std::vector< PNS::ITEM * > m_addedItems
VECTOR2< int32_t > VECTOR2I