34 #define PNSLOGINFO PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO( __FILE__, __FUNCTION__, __LINE__ ) 41 fgets( str,
sizeof( str ) - 1, f );
42 return wxString( str );
54 FILE* f = fopen( logName.c_str(),
"rb" );
61 wxStringTokenizer tokens(
readLine( f ) );
63 if( !tokens.CountTokens() )
66 wxString cmd = tokens.GetNextToken();
71 evt.
p.
x = wxAtoi( tokens.GetNextToken() );
72 evt.
p.
y = wxAtoi( tokens.GetNextToken() );
74 evt.
uuid =
KIID( tokens.GetNextToken() );
75 m_events.push_back( evt );
77 else if( cmd ==
"config" )
79 m_routerSettings->SetMode( (
PNS::PNS_MODE) wxAtoi( tokens.GetNextToken() ) );
80 m_routerSettings->SetRemoveLoops( wxAtoi( tokens.GetNextToken() ) );
81 m_routerSettings->SetFixAllSegments( wxAtoi( tokens.GetNextToken() ) );
82 m_routerSettings->SetCornerMode(
92 m_board.reset( io.
Load( boardName.c_str(),
nullptr, nullptr ) );
94 std::shared_ptr<DRC_ENGINE> drcEngine(
new DRC_ENGINE );
101 drcEngine->SetBoard( m_board.get() );
102 drcEngine->SetDesignSettings( &bds );
104 drcEngine->InitEngine( wxFileName() );
108 printf(
"parse error : %s (%s)\n", (
const char*) parse_error.
Problem().c_str(),
109 (
const char*) parse_error.
What().c_str() );
137 m_router.reset(
new ROUTER );
138 m_iface->SetBoard( m_board.get() );
139 m_router->SetInterface( m_iface.get() );
140 m_router->ClearWorld();
141 m_router->SetMode( m_mode );
142 m_router->SyncWorld();
145 m_router->Sizes().SetTrackWidth( 250000 );
149 m_debugDecorator.Clear();
150 m_iface->SetDebugDecorator( &m_debugDecorator );
163 printf(
"Router mode: %d\n", m_router->Settings().Mode() );
165 for(
auto evt : aLog->
Events() )
168 ITEM* ritem = item ? m_router->GetWorld()->FindItemByParent( item ) :
nullptr;
174 m_debugDecorator.NewStage(
"route-start", 0,
PNSLOGINFO );
175 m_debugDecorator.Message(
wxString::Format(
"route-start (%d, %d)", evt.p.x, evt.p.y ) );
176 printf(
" rtr start-route (%d, %d) %p \n", evt.p.x, evt.p.y, ritem );
177 m_router->StartRouting( evt.p, ritem, ritem ? ritem->
Layers().
Start() :
F_Cu );
183 m_debugDecorator.NewStage(
"drag-start", 0,
PNSLOGINFO );
184 m_debugDecorator.Message(
wxString::Format(
"drag-start (%d, %d)", evt.p.x, evt.p.y ) );
185 bool rv = m_router->StartDragging( evt.p, ritem, 0 );
186 printf(
" rtr start-drag (%d, %d) %p ret %d\n", evt.p.x, evt.p.y, ritem, rv ? 1 : 0 );
192 m_debugDecorator.NewStage(
"fix", 0,
PNSLOGINFO );
193 m_debugDecorator.Message(
wxString::Format(
"fix (%d, %d)", evt.p.x, evt.p.y ) );
194 bool rv = m_router->FixRoute( evt.p, ritem );
195 printf(
" fix -> (%d, %d) ret %d\n", evt.p.x, evt.p.y, rv ? 1 : 0 );
201 m_debugDecorator.NewStage(
"move", 0,
PNSLOGINFO );
202 m_debugDecorator.Message(
wxString::Format(
"move (%d, %d)", evt.p.x, evt.p.y ) );
203 printf(
" move -> (%d, %d)\n", evt.p.x, evt.p.y );
204 m_router->Move( evt.p, ritem );
217 m_debugDecorator.BeginGroup(
"current route",
PNSLOGINFO );
219 auto traces = m_router->Placer()->Traces();
221 for(
const auto& t : traces.CItems() )
223 const LINE *l = static_cast<LINE*>(t.item);
224 const auto& sh = l->
CLine();
226 m_debugDecorator.AddLine( sh,
YELLOW, l->
Width(),
"line seg",
233 node = m_router->Placer()->CurrentNode(
true );
237 node = m_router->GetDragger()->CurrentNode();
248 if( ! added.empty() )
251 m_debugDecorator.BeginGroup(
"node-added-items",
PNSLOGINFO );
253 for(
auto t : added )
257 auto s = static_cast<PNS::SEGMENT*>( t );
265 PNS::ARC* arc = static_cast<PNS::ARC*>( t );
281 if( m_stages.empty() )
282 m_stages.push_back(
new STAGE() );
284 return m_stages.back();
291 STAGE* st = currentStage();
299 m_activeEntry->AddChild( ent );
302 printf(
"LOG BeginGroup %s %p\n",
name.c_str(), ent );
311 printf(
"LOG EndGroup\n" );
316 m_activeEntry = m_activeEntry->m_parent;
324 auto st = currentStage();
325 m_activeEntry->AddChild( ent );
342 int aSize,
const std::string& aName,
347 sh->
Append( aP.
x - aSize, aP.
y - aSize );
348 sh->Append( aP.
x + aSize, aP.
y + aSize );
349 sh->Append( aP.
x, aP.
y );
350 sh->Append( aP.
x - aSize, aP.
y + aSize );
351 sh->Append( aP.
x + aSize, aP.
y - aSize );
368 int aWidth,
const std::string& aName,
386 const std::string& aName,
392 ent->m_shapes.push_back( sh );
393 ent->m_color = aColor;
394 ent->m_width = 10000;
396 ent->m_iter = m_iter;
397 ent->m_srcLoc = aSrcLoc;
409 ent->m_shapes.push_back( sh );
410 ent->m_color = aColor;
411 ent->m_width = 10000;
413 ent->m_iter = m_iter;
414 ent->m_srcLoc = aSrcLoc;
422 ent->
m_msg = msg.c_str();
435 m_stages.push_back(
new STAGE);
436 m_activeEntry = m_stages.back()->m_entries;
443 if( !visitor(
this ) )
447 for(
auto child : m_children )
449 child->IterateTree( visitor, depth + 1 );
456 STAGE* st = m_stages[stage];
460 auto visitor = [&](
DEBUG_ENT* ent ) ->
bool {
461 for(
auto sh : ent->m_shapes )
466 bb.
Merge( sh->BBox() );
const SHAPE_LINE_CHAIN & CLine() const
bool Load(const std::string &logName, const std::string boardName)
Base class for PNS router board items.
Contain all persistent settings of the router, such as the mode, optimization effort,...
Design Rule Checker object that performs all the DRC tests.
Keep the router "world" - i.e.
static const wxString readLine(FILE *f)
void addEntry(DEBUG_ENT *ent)
int Width() const override
std::vector< SHAPE * > m_shapes
std::vector< EVENT_ENTRY > & Events()
A PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
std::shared_ptr< BOARD > GetBoard() const
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
BOARD_CONNECTED_ITEM * ItemById(const EVENT_ENTRY &evt)
PNS::ROUTING_SETTINGS * GetRoutingSettings() const
virtual const wxString Problem() const
what was the problem?
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
virtual void NewStage(const std::string &name, int iter, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
virtual const wxString What() const
A composite of Problem() and Where()
void SetMode(PNS::ROUTER_MODE mode)
coord_type GetWidth() const
PNS::LOGGER::EVENT_TYPE type
virtual void AddBox(const BOX2I &aB, const KIGFX::COLOR4D &aColor, const std::string &aName, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
BOX2I GetStageExtents(int stage) const
const Vec & GetPosition() const
BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr) override
Load information from some input file format that this PLUGIN implementation knows about into either ...
virtual void AddSegment(const SEG &aS, const KIGFX::COLOR4D &aColor, const std::string &aName, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
void IterateTree(std::function< bool(DEBUG_ENT *)> visitor, int depth=0)
PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO m_srcLoc
virtual void Message(const wxString &msg, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
A filename or source description, a problem input line, a line number, a byte offset,...
virtual void AddPoint(const VECTOR2I &aP, const KIGFX::COLOR4D &aColor, int aSize, const std::string &aName, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
virtual void BeginGroup(const std::string &name, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
virtual void EndGroup(const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
int Width() const
Return true if the line is geometrically identical as line aOther.
coord_type GetHeight() const
void GetUpdatedItems(ITEM_VECTOR &aRemoved, ITEM_VECTOR &aAdded)
Return the list of items removed and added in this branch with respect to the root branch.
virtual void AddLine(const SHAPE_LINE_CHAIN &aLine, const KIGFX::COLOR4D &aColor, int aWidth, const std::string &aName, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
Push and Shove diff pair dimensions (gap) settings dialog.
void ReplayLog(PNS_LOG_FILE *aLog, int aStartEventIndex=0, int aFrom=0, int aTo=-1)
std::shared_ptr< DRC_ENGINE > m_DRCEngine
const LAYER_RANGE & Layers() const
std::vector< ITEM * > ITEM_VECTOR
Container for design settings for a BOARD object.
A color representation with 4 components: red, green, blue, alpha.