diff --git a/pcbnew/router/pns_diff_pair_placer.cpp b/pcbnew/router/pns_diff_pair_placer.cpp index 2aa92057d5..6aac065b1e 100644 --- a/pcbnew/router/pns_diff_pair_placer.cpp +++ b/pcbnew/router/pns_diff_pair_placer.cpp @@ -396,7 +396,7 @@ bool PNS_DIFF_PAIR_PLACER::SetLayer( int aLayer ) { m_currentLayer = aLayer; m_start = *m_prevPair; - initPlacement( false ); + initPlacement(); Move( m_currentEnd, NULL ); return true; } @@ -559,11 +559,6 @@ bool PNS_DIFF_PAIR_PLACER::Start( const VECTOR2I& aP, PNS_ITEM* aStartItem ) { VECTOR2I p( aP ); - bool split; - - if( Router()->SnappingEnabled() ) - p = Router()->SnapToItem( aStartItem, aP, split ); - if( !aStartItem ) { Router()->SetFailureReason( _( "Can't start a differential pair " @@ -612,13 +607,13 @@ bool PNS_DIFF_PAIR_PLACER::Start( const VECTOR2I& aP, PNS_ITEM* aStartItem ) m_placingVia = false; m_chainedPlacement = false; - initPlacement( false ); + initPlacement(); return true; } -void PNS_DIFF_PAIR_PLACER::initPlacement( bool aSplitSeg ) +void PNS_DIFF_PAIR_PLACER::initPlacement( ) { m_idle = false; m_orthoMode = false; diff --git a/pcbnew/router/pns_diff_pair_placer.h b/pcbnew/router/pns_diff_pair_placer.h index 9bbed4cbcd..e5e31957b3 100644 --- a/pcbnew/router/pns_diff_pair_placer.h +++ b/pcbnew/router/pns_diff_pair_placer.h @@ -199,7 +199,7 @@ private: * * Initializes placement of a new line with given parameters. */ - void initPlacement( bool aSplitSeg = false ); + void initPlacement( ); /** * Function setInitialDirection() diff --git a/pcbnew/router/pns_line_placer.cpp b/pcbnew/router/pns_line_placer.cpp index 050123dd12..15af272421 100644 --- a/pcbnew/router/pns_line_placer.cpp +++ b/pcbnew/router/pns_line_placer.cpp @@ -52,7 +52,6 @@ PNS_LINE_PLACER::PNS_LINE_PLACER( PNS_ROUTER* aRouter ) : m_currentMode = RM_MarkObstacles; m_startItem = NULL; m_chainedPlacement = false; - m_splitSeg = false; m_orthoMode = false; } @@ -688,26 +687,29 @@ PNS_NODE* PNS_LINE_PLACER::CurrentNode( bool aLoopsRemoved ) const void PNS_LINE_PLACER::splitAdjacentSegments( PNS_NODE* aNode, PNS_ITEM* aSeg, const VECTOR2I& aP ) { - if( aSeg && aSeg->OfKind( PNS_ITEM::SEGMENT ) ) - { - PNS_JOINT* jt = aNode->FindJoint( aP, aSeg ); + if( !aSeg ) + return; - if( jt && jt->LinkCount() >= 1 ) - return; + if( !aSeg->OfKind( PNS_ITEM::SEGMENT ) ) + return; - PNS_SEGMENT* s_old = static_cast( aSeg ); - PNS_SEGMENT* s_new[2]; + PNS_JOINT* jt = aNode->FindJoint( aP, aSeg ); - s_new[0] = s_old->Clone(); - s_new[1] = s_old->Clone(); + if( jt && jt->LinkCount() >= 1 ) + return; - s_new[0]->SetEnds( s_old->Seg().A, aP ); - s_new[1]->SetEnds( aP, s_old->Seg().B ); + PNS_SEGMENT* s_old = static_cast( aSeg ); + PNS_SEGMENT* s_new[2]; - aNode->Remove( s_old ); - aNode->Add( s_new[0], true ); - aNode->Add( s_new[1], true ); - } + s_new[0] = s_old->Clone(); + s_new[1] = s_old->Clone(); + + s_new[0]->SetEnds( s_old->Seg().A, aP ); + s_new[1]->SetEnds( aP, s_old->Seg().B ); + + aNode->Remove( s_old ); + aNode->Add( s_new[0], true ); + aNode->Add( s_new[1], true ); } @@ -724,8 +726,7 @@ bool PNS_LINE_PLACER::SetLayer( int aLayer ) } else if( !m_startItem || ( m_startItem->OfKind( PNS_ITEM::VIA ) && m_startItem->Layers().Overlaps( aLayer ) ) ) { m_currentLayer = aLayer; - m_splitSeg = false; - initPlacement ( m_splitSeg ); + initPlacement ( ); Move ( m_currentEnd, NULL ); return true; } @@ -741,11 +742,6 @@ bool PNS_LINE_PLACER::Start( const VECTOR2I& aP, PNS_ITEM* aStartItem ) static int unknowNetIdx = 0; // -10000; int net = -1; - bool splitSeg = false; - - if( Router()->SnappingEnabled() ) - p = Router()->SnapToItem( aStartItem, aP, splitSeg ); - if( !aStartItem || aStartItem->Net() < 0 ) net = unknowNetIdx--; else @@ -757,15 +753,14 @@ bool PNS_LINE_PLACER::Start( const VECTOR2I& aP, PNS_ITEM* aStartItem ) m_startItem = aStartItem; m_placingVia = false; m_chainedPlacement = false; - m_splitSeg = splitSeg; setInitialDirection( Settings().InitialDirection() ); - initPlacement( m_splitSeg ); + initPlacement( ); return true; } -void PNS_LINE_PLACER::initPlacement( bool aSplitSeg ) +void PNS_LINE_PLACER::initPlacement( ) { m_idle = false; @@ -788,8 +783,7 @@ void PNS_LINE_PLACER::initPlacement( bool aSplitSeg ) world->KillChildren(); PNS_NODE* rootNode = world->Branch(); - if( aSplitSeg ) - splitAdjacentSegments( rootNode, m_startItem, m_currentStart ); + splitAdjacentSegments( rootNode, m_startItem, m_currentStart ); setWorld( rootNode ); @@ -927,7 +921,6 @@ bool PNS_LINE_PLACER::FixRoute( const VECTOR2I& aP, PNS_ITEM* aEndItem ) m_startItem = NULL; m_placingVia = false; m_chainedPlacement = !pl.EndsWithVia(); - m_splitSeg = false; initPlacement(); } else @@ -1015,7 +1008,7 @@ void PNS_LINE_PLACER::UpdateSizes( const PNS_SIZES_SETTINGS& aSizes ) if( !m_idle ) { - initPlacement( m_splitSeg ); + initPlacement( ); } } diff --git a/pcbnew/router/pns_line_placer.h b/pcbnew/router/pns_line_placer.h index 8a1f263910..c56ff1f741 100644 --- a/pcbnew/router/pns_line_placer.h +++ b/pcbnew/router/pns_line_placer.h @@ -222,7 +222,7 @@ private: * * Initializes placement of a new line with given parameters. */ - void initPlacement( bool aSplitSeg = false ); + void initPlacement( ); /** * Function setInitialDirection() @@ -390,7 +390,6 @@ private: bool m_idle; bool m_chainedPlacement; - bool m_splitSeg; bool m_orthoMode; }; diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index 85474b6e85..264d9f1a8b 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -83,8 +83,6 @@ PNS_ROUTER::PNS_ROUTER() m_view = NULL; m_snappingEnabled = false; m_violation = false; -// m_gridHelper = NULL; - } @@ -142,63 +140,6 @@ const PNS_ITEMSET PNS_ROUTER::QueryHoverItems( const VECTOR2I& aP ) } } - -const VECTOR2I PNS_ROUTER::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( aItem )->Pos(); - aSplitsSegment = false; - break; - - case PNS_ITEM::VIA: - anchor = static_cast( aItem )->Pos(); - aSplitsSegment = false; - break; - - case PNS_ITEM::SEGMENT: - { - PNS_SEGMENT* seg = static_cast( 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 - { -// fixme: alignment! - anchor = s.NearestPoint( aP ); - aSplitsSegment = true; - -// anchor = m_gridHelper->AlignToSegment ( aP, s ); - // aSplitsSegment = (anchor != s.A && anchor != s.B ); - - } - - break; - } - - default: - break; - } - - return anchor; -} - - bool PNS_ROUTER::StartDragging( const VECTOR2I& aP, PNS_ITEM* aStartItem ) { if( !aStartItem || aStartItem->OfKind( PNS_ITEM::SOLID ) ) diff --git a/pcbnew/router/pns_router.h b/pcbnew/router/pns_router.h index d0e17974eb..7ff3f71180 100644 --- a/pcbnew/router/pns_router.h +++ b/pcbnew/router/pns_router.h @@ -34,7 +34,6 @@ #include "pns_itemset.h" #include "pns_node.h" -class GRID_HELPER; class PNS_DEBUG_DECORATOR; class PNS_NODE; class PNS_DIFF_PAIR_PLACER; @@ -214,11 +213,6 @@ public: PNS_PLACEMENT_ALGO *Placer() { return m_placer; } - void SetGrid( GRID_HELPER *aGridHelper ) - { - m_gridHelper = aGridHelper; - } - PNS_ROUTER_IFACE *GetInterface() const { return m_iface; @@ -276,8 +270,6 @@ private: wxString m_toolStatusbarName; wxString m_failureReason; - - GRID_HELPER *m_gridHelper; }; #endif diff --git a/pcbnew/router/pns_tool_base.cpp b/pcbnew/router/pns_tool_base.cpp index fc66da12d2..deee098440 100644 --- a/pcbnew/router/pns_tool_base.cpp +++ b/pcbnew/router/pns_tool_base.cpp @@ -48,6 +48,8 @@ using namespace std::placeholders; #include "pns_kicad_iface.h" #include "pns_tool_base.h" #include "pns_segment.h" +#include "pns_solid.h" +#include "pns_via.h" #include "pns_router.h" #include "pns_meander_placer.h" // fixme: move settings to separate header #include "pns_tune_status_popup.h" @@ -114,7 +116,6 @@ void PNS_TOOL_BASE::Reset( RESET_REASON aReason ) m_router->UpdateSizes( m_savedSizes ); m_gridHelper = new GRID_HELPER( m_frame ); - m_router->SetGrid( m_gridHelper ); } @@ -228,7 +229,7 @@ void PNS_TOOL_BASE::updateStartItem( TOOL_EVENT& aEvent ) if( startItem && startItem->Net() >= 0 ) { bool dummy; - VECTOR2I psnap = m_router->SnapToItem( startItem, p, dummy ); + VECTOR2I psnap = snapToItem( startItem, p, dummy ); if( snapEnabled ) { @@ -290,7 +291,7 @@ void PNS_TOOL_BASE::updateEndItem( TOOL_EVENT& aEvent ) if( endItem ) { - VECTOR2I cursorPos = m_router->SnapToItem( endItem, p, dummy ); + VECTOR2I cursorPos = snapToItem( endItem, p, dummy ); m_ctls->ForceCursorPosition( true, cursorPos ); m_endItem = endItem; m_endSnapPoint = cursorPos; @@ -333,3 +334,56 @@ PNS_ROUTER *PNS_TOOL_BASE::Router() const { return m_router; } + +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( aItem )->Pos(); + aSplitsSegment = false; + break; + + case PNS_ITEM::VIA: + anchor = static_cast( aItem )->Pos(); + aSplitsSegment = false; + break; + + case PNS_ITEM::SEGMENT: + { + PNS_SEGMENT* seg = static_cast( 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; +} diff --git a/pcbnew/router/pns_tool_base.h b/pcbnew/router/pns_tool_base.h index 5ecea863b7..f5987e4c9c 100644 --- a/pcbnew/router/pns_tool_base.h +++ b/pcbnew/router/pns_tool_base.h @@ -54,6 +54,7 @@ public: protected: + const VECTOR2I snapToItem( PNS_ITEM* aItem, VECTOR2I aP, bool& aSplitsSegment ); virtual PNS_ITEM* pickSingleItem( const VECTOR2I& aWhere, int aNet = -1, int aLayer = -1 ); virtual void highlightNet( bool aEnabled, int aNetcode = -1 ); virtual void updateStartItem( TOOL_EVENT& aEvent ); @@ -77,8 +78,6 @@ protected: GRID_HELPER* m_gridHelper; PNS_KICAD_IFACE *m_iface; PNS_ROUTER *m_router; - - }; #endif