28#include <wx/filename.h>
30#include <wx/stdstream.h>
31#include <wx/wfstream.h>
51 std::vector<BOARD_CONNECTED_ITEM*> parents;
53 parents.resize( evt.
uuids.size() );
57 for(
int i = 0; i < evt.
uuids.size(); i++ )
59 if( item->m_Uuid == evt.
uuids[i] )
73 if ( parents.size() > 0 )
83 fgets( str,
sizeof( str ) - 1, f );
84 return wxString( str );
89 m_mode(
PNS::ROUTER_MODE::PNS_MODE_ROUTE_SINGLE )
97 const wxString type =
static_cast<wxString
>( aJSON.at(
"type" ).get<wxString>() );
99 if( type == wxT(
"segment") )
102 sh->SetSeg(
SEG( aJSON.at(
"start" ).get<
VECTOR2I>(), aJSON.at(
"end" ).get<
VECTOR2I>() ) );
103 sh->SetWidth( aJSON.at(
"width" ).get<
int>() );
106 else if( type == wxT(
"circle") )
109 sh->SetCenter( aJSON.at(
"center" ).get<
VECTOR2I>() );
110 sh->SetRadius( aJSON.at(
"radius" ).get<
int>() );
113 else if( type == wxT(
"arc") )
118 int width = aJSON.at(
"width" ).get<
int>();
120 std::shared_ptr<SHAPE_ARC> sh(
new SHAPE_ARC( start, mid,
end, width ) );
136 a.
x = wxAtoi( aTokens.GetNextToken() );
137 a.
y = wxAtoi( aTokens.GetNextToken() );
138 b.
x = wxAtoi( aTokens.GetNextToken() );
139 b.
y = wxAtoi( aTokens.GetNextToken() );
140 int width = wxAtoi( aTokens.GetNextToken() );
141 sh->SetSeg(
SEG( a, b ));
142 sh->SetWidth( width );
149 a.
x = wxAtoi( aTokens.GetNextToken() );
150 a.
y = wxAtoi( aTokens.GetNextToken() );
151 int radius = wxAtoi( aTokens.GetNextToken() );
161 wxStringTokenizer& aTokens )
163 if( cmd == wxS(
"net" ) )
165 aItem->
SetNet(
m_board->FindNet( wxAtoi( aTokens.GetNextToken() ) ) );
168 else if( cmd == wxS(
"layers" ) )
170 int start = wxAtoi( aTokens.GetNextToken() );
171 int end = wxAtoi( aTokens.GetNextToken() );
181 aItem->
SetNet(
m_board->FindNet( aJSON.at(
"net" ).get<wxString>() ) );
183 PNS_LAYER_RANGE( aJSON.at(
"layers" ).at( 0 ).get<
int>(), aJSON.at(
"layers" ).at( 1 ).get<
int>() ) );
190 std::unique_ptr<PNS::SEGMENT> seg(
new PNS::SEGMENT() );
192 while( aTokens.CountTokens() )
194 wxString cmd = aTokens.GetNextToken();
198 if( cmd == wxS(
"shape" ) )
218 while( aTokens.CountTokens() )
220 wxString cmd = aTokens.GetNextToken();
224 if( cmd == wxS(
"shape" ) )
236 else if( cmd == wxS(
"drill" ) )
238 via->SetDrill( wxAtoi( aTokens.GetNextToken() ) );
248 wxString kind = aJSON.at(
"kind").get<wxString>();
250 if( kind == wxT(
"segment") )
252 auto parsedShape =
parseShape( aJSON.at(
"shape") );
257 auto shape =
static_cast<const SHAPE_SEGMENT*
>( parsedShape.get() );
258 std::unique_ptr<PNS::SEGMENT> seg(
new PNS::SEGMENT( *shape,
nullptr ) );
260 return std::move( seg );
262 else if ( kind == wxT(
"arc" ) )
264 auto parsedShape =
parseShape( aJSON.at(
"shape") );
269 auto shape =
static_cast<const SHAPE_ARC*
>( parsedShape.get() );
270 std::unique_ptr<PNS::ARC> arc(
new PNS::ARC( *shape,
nullptr ) );
272 return std::move( arc );
274 else if ( kind == wxT(
"via" ) )
276 auto parsedShape =
parseShape( aJSON.at(
"shape") );
281 auto shape =
static_cast<const SHAPE_CIRCLE*
>( parsedShape.get() );
284 via->SetPos( shape->Centre() );
285 via->SetDiameter(
via->Layers().Start(), shape->GetRadius() * 2 );
286 via->SetDrill( aJSON.at(
"drill").get<
int>() );
287 return std::move(
via);
296 wxString type = aTokens.GetNextToken();
298 if( type == wxS(
"segment" ) )
300 else if( type == wxS(
"via" ) )
311 if( a->
Net() != b->
Net() )
329 if( va->
Pos() != vb->
Pos() )
338 if( sa->
Seg() != sb->
Seg() )
349const std::set<PNS::ITEM*>
deduplicate(
const std::vector<PNS::ITEM*>& items )
351 std::set<PNS::ITEM*> rv;
355 bool isDuplicate =
false;
398 chkAddedItems.erase( chk );
406 if( chkAddedItems.empty() && check.
m_removedIds.empty() )
427 wxFFileOutputStream fp( logFileName.GetFullPath(), wxT(
"wt" ) );
433 aRpt->
Report( wxString::Format( wxT(
"Failed to write log file: %s"), logFileName.GetFullPath() ),
RPT_SEVERITY_ERROR );
438 wxScopedCharBuffer utf8 = logString.ToUTF8();
439 fp.Write( utf8.data(), utf8.length() );
448 wxFileName fname_log( logFileName );
449 fname_log.SetExt( wxT(
"log" ) );
451 wxFileName fname_dump( logFileName );
452 fname_dump.SetExt( wxT(
"dump" ) );
454 if( !boardFileName.IsEmpty() )
456 fname_dump = boardFileName;
459 wxFileName fname_project( logFileName );
460 fname_project.SetExt( wxT(
"kicad_pro" ) );
461 fname_project.MakeAbsolute();
463 wxFileName fname_settings( logFileName );
464 fname_settings.SetExt( wxT(
"settings" ) );
466 aRpt->
Report( wxString::Format( wxT(
"Loading router settings from '%s'" ),
467 fname_settings.GetFullPath() ) );
469 bool ok =
m_routerSettings->LoadFromRawFile( fname_settings.GetFullPath() );
473 aRpt->
Report( wxT(
"Failed to load routing settings. Using defaults." ),
477 aRpt->
Report( wxString::Format( wxT(
"Loading project settings from '%s'" ),
478 fname_settings.GetFullPath() ) );
488 aRpt->
Report( wxString::Format( wxT(
"Loading board snapshot from '%s'"),
489 fname_dump.GetFullPath() ) );
491 m_board.reset( io.
LoadBoard( fname_dump.GetFullPath(),
nullptr,
nullptr ) );
494 std::shared_ptr<DRC_ENGINE> drcEngine(
new DRC_ENGINE );
501 m_board->SynchronizeNetsAndNetClasses(
true );
503 drcEngine->SetBoard(
m_board.get() );
504 drcEngine->SetDesignSettings( &bds );
505 drcEngine->SetLogReporter( aRpt );
508 wxFileName fname_rules( logFileName );
511 if( fname_rules.FileExists() )
512 drcEngine->InitEngine( fname_rules );
514 drcEngine->InitEngine( wxFileName() );
518 aRpt->
Report( wxString::Format(
"parse error : %s (%s)\n",
520 parse_error.
What() ),
527 ok =
loadJsonLog( logFileName.GetFullPath(), aRpt,
false );
528 if( !ok && logFileName.FileExists() )
540 wxFFileInputStream fp( aFilename, wxT(
"rt" ) );
541 wxStdInputStream fstream( fp );
546 aRpt->
Report( wxString::Format(
"Loading log from: %s", aFilename ) );
559 nlohmann::json logJson = nlohmann::json::parse( fstream,
nullptr,
563 if( logJson.contains(
"board_hash") )
565 m_boardHash = logJson.at(
"board_hash").get<wxString>();
568 if( logJson.contains(
"test_case_type") )
578 for(
const nlohmann::json& event : logJson.at(
"events" ) )
583 for(
const nlohmann::json& addedItem : logJson.at(
"addedItems" ) )
589 for(
const nlohmann::json& addedItem : logJson.at(
"removedItems" ) )
596 aRpt->
Report( wxString::Format(
"JSON log load: %lu events, %lu added, %lu removed\n",
m_events.size(),
603 catch(
const std::exception& exc )
618 FILE* f = fopen( aFilename.c_str(),
"rb" );
620 aRpt->
Report( wxString::Format(
"Loading log from '%s'", aFilename ) );
633 wxStringTokenizer tokens( line );
635 if( !tokens.CountTokens() )
638 wxString cmd = tokens.GetNextToken();
640 if( cmd == wxT(
"mode" ) )
644 else if( cmd == wxT(
"event" ) )
648 else if( cmd == wxT(
"added" ) )
653 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
static const std::string DesignRulesFileExtension
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
Definition of file extensions used in Kicad.