void ROUTER_PREVIEW_ITEM::Update( const PNS_ITEM* aItem ) { m_originLayer = aItem->Layers().Start(); if( aItem->OfKind ( PNS_ITEM::LINE ) ) { const PNS_LINE* l=static_cast<const PNS_LINE*>( aItem ); if( !l->SegmentCount() ) return; } assert( m_originLayer >= 0 ); m_layer = m_originLayer; m_color = getLayerColor( m_originLayer ); m_color.a = 0.8; m_depth = BaseOverlayDepth - aItem->Layers().Start(); m_shape = aItem->Shape()->Clone(); switch( aItem->Kind() ) { case PNS_ITEM::LINE: m_type = PR_SHAPE; m_width = ( (PNS_LINE*) aItem )->Width(); break; case PNS_ITEM::SEGMENT: { PNS_SEGMENT* seg = (PNS_SEGMENT*) aItem; m_type = PR_SHAPE; m_width = seg->Width(); break; } case PNS_ITEM::VIA: m_originLayer = m_layer = ITEM_GAL_LAYER( VIAS_VISIBLE ); m_type = PR_SHAPE; m_width = 0; m_color = COLOR4D( 0.7, 0.7, 0.7, 0.8 ); m_depth = ViaOverlayDepth; break; case PNS_ITEM::SOLID: m_type = PR_SHAPE; m_width = 0; break; default: break; } if( aItem->Marker() & MK_VIOLATION ) m_color = COLOR4D( 0, 1, 0, 1 ); if( aItem->Marker() & MK_HEAD ) m_color.Brighten( 0.7 ); ViewSetVisible( true ); ViewUpdate( GEOMETRY | APPEARANCE ); }
const PNS_TOPOLOGY::JOINT_SET PNS_TOPOLOGY::ConnectedJoints( PNS_JOINT* aStart ) { std::deque<PNS_JOINT*> searchQueue; JOINT_SET processed; searchQueue.push_back( aStart ); processed.insert( aStart ); while( !searchQueue.empty() ) { PNS_JOINT* current = searchQueue.front(); searchQueue.pop_front(); for( PNS_ITEM* item : current->LinkList() ) { if( item->OfKind( PNS_ITEM::SEGMENT ) ) { PNS_SEGMENT* seg = static_cast<PNS_SEGMENT*>( item ); PNS_JOINT* a = m_world->FindJoint( seg->Seg().A, seg ); PNS_JOINT* b = m_world->FindJoint( seg->Seg().B, seg ); PNS_JOINT* next = ( *a == *current ) ? b : a; if( processed.find( next ) == processed.end() ) { processed.insert( next ); searchQueue.push_back( next ); } } } } return processed; }
OPT_VECTOR2I PNS_DIFF_PAIR_PLACER::getDanglingAnchor( PNS_NODE* aNode, PNS_ITEM* aItem ) { switch( aItem->Kind() ) { case PNS_ITEM::VIA: case PNS_ITEM::SOLID: return aItem->Anchor( 0 ); case PNS_ITEM::SEGMENT: { PNS_SEGMENT* s =static_cast<PNS_SEGMENT*>( aItem ); PNS_JOINT* jA = aNode->FindJoint( s->Seg().A, s ); PNS_JOINT* jB = aNode->FindJoint( s->Seg().B, s ); if( jA->LinkCount() == 1 ) return s->Seg().A; else if( jB->LinkCount() == 1 ) return s->Seg().B; else return OPT_VECTOR2I(); } default: return OPT_VECTOR2I(); break; } }
PNS_ITEM* PNS_ROUTER::syncTrack( TRACK* aTrack ) { PNS_SEGMENT* s = new PNS_SEGMENT( SEG( aTrack->GetStart(), aTrack->GetEnd() ), aTrack->GetNetCode() ); s->SetWidth( aTrack->GetWidth() ); s->SetLayers( PNS_LAYERSET( aTrack->GetLayer() ) ); s->SetParent( aTrack ); return s; }
const VECTOR2I PNS_TOOL_BASE::snapToItem( PNS_ITEM* aItem, VECTOR2I aP, bool& aSplitsSegment ) { VECTOR2I anchor; if( !aItem ) { aSplitsSegment = false; return aP; } switch( aItem->Kind() ) { case PNS_ITEM::SOLID: anchor = static_cast<PNS_SOLID*>( aItem )->Pos(); aSplitsSegment = false; break; case PNS_ITEM::VIA: anchor = static_cast<PNS_VIA*>( aItem )->Pos(); aSplitsSegment = false; break; case PNS_ITEM::SEGMENT: { PNS_SEGMENT* seg = static_cast<PNS_SEGMENT*>( aItem ); const SEG& s = seg->Seg(); int w = seg->Width(); aSplitsSegment = false; if( ( aP - s.A ).EuclideanNorm() < w / 2 ) anchor = s.A; else if( ( aP - s.B ).EuclideanNorm() < w / 2 ) anchor = s.B; else { anchor = s.NearestPoint( aP ); aSplitsSegment = true; anchor = m_gridHelper->AlignToSegment( aP, s ); aSplitsSegment = ( anchor != s.A && anchor != s.B ); } break; } default: break; } return anchor; }
DIRECTION_45 PNS_DP_PRIMITIVE_PAIR::anchorDirection( PNS_ITEM* aItem, const VECTOR2I& aP ) const { if( !aItem->OfKind ( PNS_ITEM::SEGMENT ) ) return DIRECTION_45(); PNS_SEGMENT* s = static_cast<PNS_SEGMENT*>( aItem ); if( s->Seg().A == aP ) return DIRECTION_45( s->Seg().A - s->Seg().B ); else return DIRECTION_45( s->Seg().B - s->Seg().A ); }
void PNS_LOGGER::Log ( const PNS_ITEM* aItem, int aKind, const std::string aName ) { m_theLog << "aItem " << aKind << " " << aName << " "; m_theLog << aItem->Net() << " " << aItem->Layers().Start() << " " << aItem->Layers().End() << " " << aItem->Marker() << " " << aItem->Rank(); switch( aItem->Kind() ) { case PNS_ITEM::LINE: { PNS_LINE* l = (PNS_LINE*) aItem; m_theLog << " line "; m_theLog << l->Width() << " " << ( l->EndsWithVia() ? 1 : 0 ) << " "; dumpShape ( l->Shape() ); m_theLog << std::endl; break; } case PNS_ITEM::VIA: { m_theLog << " via 0 0 "; dumpShape ( aItem->Shape() ); m_theLog << std::endl; break; } case PNS_ITEM::SEGMENT: { PNS_SEGMENT* s =(PNS_SEGMENT*) aItem; m_theLog << " line "; m_theLog << s->Width() << " 0 linechain 2 0 " << s->Seg().A.x << " " << s->Seg().A.y << " " << s->Seg().B.x << " " <<s->Seg().B.y << std::endl; break; } case PNS_ITEM::SOLID: { PNS_SOLID* s = (PNS_SOLID*) aItem; m_theLog << " solid 0 0 "; dumpShape( s->Shape() ); m_theLog << std::endl; break; } default: break; } }
bool PNS_TOPOLOGY::AssembleDiffPair( PNS_ITEM* aStart, PNS_DIFF_PAIR& aPair ) { int refNet = aStart->Net(); int coupledNet = DpCoupledNet( refNet ); if( coupledNet < 0 ) return false; std::set<PNS_ITEM*> coupledItems; m_world->AllItemsInNet( coupledNet, coupledItems ); PNS_SEGMENT* coupledSeg = NULL, *refSeg; int minDist = std::numeric_limits<int>::max(); if( ( refSeg = dyn_cast<PNS_SEGMENT*>( aStart ) ) != NULL ) { for( PNS_ITEM* item : coupledItems ) { if( PNS_SEGMENT* s = dyn_cast<PNS_SEGMENT*>( item ) ) { if( s->Layers().Start() == refSeg->Layers().Start() && s->Width() == refSeg->Width() ) { int dist = s->Seg().Distance( refSeg->Seg() ); bool isParallel = refSeg->Seg().ApproxParallel( s->Seg() ); SEG p_clip, n_clip; bool isCoupled = commonParallelProjection( refSeg->Seg(), s->Seg(), p_clip, n_clip ); if( isParallel && isCoupled && dist < minDist ) { minDist = dist; coupledSeg = s; } } } } } else { return false; } if( !coupledSeg ) return false; PNS_LINE lp = m_world->AssembleLine( refSeg ); PNS_LINE ln = m_world->AssembleLine( coupledSeg ); if( DpNetPolarity( refNet ) < 0 ) { std::swap( lp, ln ); } int gap = -1; if( refSeg->Seg().ApproxParallel( coupledSeg->Seg() ) ) { // Segments are parallel -> compute pair gap const VECTOR2I refDir = refSeg->Anchor( 1 ) - refSeg->Anchor( 0 ); const VECTOR2I displacement = refSeg->Anchor( 1 ) - coupledSeg->Anchor( 1 ); gap = (int) std::abs( refDir.Cross( displacement ) / refDir.EuclideanNorm() ) - lp.Width(); } aPair = PNS_DIFF_PAIR( lp, ln ); aPair.SetWidth( lp.Width() ); aPair.SetLayers( lp.Layers() ); aPair.SetGap( gap ); return true; }
bool PNS_LINE_PLACER::FixRoute( const VECTOR2I& aP, PNS_ITEM* aEndItem ) { bool realEnd = false; int lastV; PNS_LINE pl = Trace(); if( m_currentMode == RM_MarkObstacles && !Settings().CanViolateDRC() && m_world->CheckColliding( &pl ) ) return false; const SHAPE_LINE_CHAIN& l = pl.CLine(); if( !l.SegmentCount() ) { if( pl.EndsWithVia() ) { m_lastNode->Add( pl.Via().Clone() ); Router()->CommitRouting( m_lastNode ); m_lastNode = NULL; m_currentNode = NULL; m_idle = true; } return true; } VECTOR2I p_pre_last = l.CPoint( -1 ); const VECTOR2I p_last = l.CPoint( -1 ); DIRECTION_45 d_last( l.CSegment( -1 ) ); if( l.PointCount() > 2 ) p_pre_last = l.CPoint( -2 ); if( aEndItem && m_currentNet >= 0 && m_currentNet == aEndItem->Net() ) realEnd = true; if( realEnd || m_placingVia ) lastV = l.SegmentCount(); else lastV = std::max( 1, l.SegmentCount() - 1 ); PNS_SEGMENT* lastSeg = NULL; for( int i = 0; i < lastV; i++ ) { const SEG& s = pl.CSegment( i ); PNS_SEGMENT* seg = new PNS_SEGMENT( s, m_currentNet ); seg->SetWidth( pl.Width() ); seg->SetLayer( m_currentLayer ); m_lastNode->Add( seg ); lastSeg = seg; } if( pl.EndsWithVia() ) m_lastNode->Add( pl.Via().Clone() ); if( realEnd ) simplifyNewLine( m_lastNode, lastSeg ); Router()->CommitRouting( m_lastNode ); m_lastNode = NULL; m_currentNode = NULL; if( !realEnd ) { setInitialDirection( d_last ); m_currentStart = m_placingVia ? p_last : p_pre_last; m_startItem = NULL; m_placingVia = false; m_chainedPlacement = !pl.EndsWithVia(); m_splitSeg = false; initPlacement(); } else { m_idle = true; } return realEnd; }
void PNS_ROUTER::CommitRouting( PNS_NODE* aNode ) { PNS_NODE::ITEM_VECTOR removed, added; aNode->GetUpdatedItems( removed, added ); for( unsigned int i = 0; i < removed.size(); i++ ) { BOARD_CONNECTED_ITEM* parent = removed[i]->Parent(); if( parent ) { m_view->Remove( parent ); m_board->Remove( parent ); m_undoBuffer.PushItem( ITEM_PICKER( parent, UR_DELETED ) ); } } for( PNS_ITEM* item : added ) { BOARD_CONNECTED_ITEM* newBI = NULL; switch( item->Kind() ) { case PNS_ITEM::SEGMENT: { PNS_SEGMENT* seg = static_cast<PNS_SEGMENT*>( item ); TRACK* track = new TRACK( m_board ); const SEG& s = seg->Seg(); track->SetStart( wxPoint( s.A.x, s.A.y ) ); track->SetEnd( wxPoint( s.B.x, s.B.y ) ); track->SetWidth( seg->Width() ); track->SetLayer( ToLAYER_ID( seg->Layers().Start() ) ); track->SetNetCode( seg->Net() > 0 ? seg->Net() : 0 ); newBI = track; break; } case PNS_ITEM::VIA: { VIA* via_board = new VIA( m_board ); PNS_VIA* via = static_cast<PNS_VIA*>( item ); via_board->SetPosition( wxPoint( via->Pos().x, via->Pos().y ) ); via_board->SetWidth( via->Diameter() ); via_board->SetDrill( via->Drill() ); via_board->SetNetCode( via->Net() > 0 ? via->Net() : 0 ); via_board->SetViaType( via->ViaType() ); // MUST be before SetLayerPair() via_board->SetLayerPair( ToLAYER_ID( via->Layers().Start() ), ToLAYER_ID( via->Layers().End() ) ); newBI = via_board; break; } default: break; } if( newBI ) { item->SetParent( newBI ); newBI->ClearFlags(); m_view->Add( newBI ); m_board->Add( newBI ); m_undoBuffer.PushItem( ITEM_PICKER( newBI, UR_NEW ) ); newBI->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } m_board->GetRatsnest()->Recalculate(); m_world->Commit( aNode ); }