P&S: factor out Kicad-dependend PNS_ROUTER::SnapToItem() to the PNS_TOOL_BASE class
This commit is contained in:
parent
4d134e5522
commit
a53ea81794
|
@ -396,7 +396,7 @@ bool PNS_DIFF_PAIR_PLACER::SetLayer( int aLayer )
|
||||||
{
|
{
|
||||||
m_currentLayer = aLayer;
|
m_currentLayer = aLayer;
|
||||||
m_start = *m_prevPair;
|
m_start = *m_prevPair;
|
||||||
initPlacement( false );
|
initPlacement();
|
||||||
Move( m_currentEnd, NULL );
|
Move( m_currentEnd, NULL );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -559,11 +559,6 @@ bool PNS_DIFF_PAIR_PLACER::Start( const VECTOR2I& aP, PNS_ITEM* aStartItem )
|
||||||
{
|
{
|
||||||
VECTOR2I p( aP );
|
VECTOR2I p( aP );
|
||||||
|
|
||||||
bool split;
|
|
||||||
|
|
||||||
if( Router()->SnappingEnabled() )
|
|
||||||
p = Router()->SnapToItem( aStartItem, aP, split );
|
|
||||||
|
|
||||||
if( !aStartItem )
|
if( !aStartItem )
|
||||||
{
|
{
|
||||||
Router()->SetFailureReason( _( "Can't start a differential pair "
|
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_placingVia = false;
|
||||||
m_chainedPlacement = false;
|
m_chainedPlacement = false;
|
||||||
|
|
||||||
initPlacement( false );
|
initPlacement();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PNS_DIFF_PAIR_PLACER::initPlacement( bool aSplitSeg )
|
void PNS_DIFF_PAIR_PLACER::initPlacement( )
|
||||||
{
|
{
|
||||||
m_idle = false;
|
m_idle = false;
|
||||||
m_orthoMode = false;
|
m_orthoMode = false;
|
||||||
|
|
|
@ -199,7 +199,7 @@ private:
|
||||||
*
|
*
|
||||||
* Initializes placement of a new line with given parameters.
|
* Initializes placement of a new line with given parameters.
|
||||||
*/
|
*/
|
||||||
void initPlacement( bool aSplitSeg = false );
|
void initPlacement( );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function setInitialDirection()
|
* Function setInitialDirection()
|
||||||
|
|
|
@ -52,7 +52,6 @@ PNS_LINE_PLACER::PNS_LINE_PLACER( PNS_ROUTER* aRouter ) :
|
||||||
m_currentMode = RM_MarkObstacles;
|
m_currentMode = RM_MarkObstacles;
|
||||||
m_startItem = NULL;
|
m_startItem = NULL;
|
||||||
m_chainedPlacement = false;
|
m_chainedPlacement = false;
|
||||||
m_splitSeg = false;
|
|
||||||
m_orthoMode = false;
|
m_orthoMode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -688,8 +687,12 @@ PNS_NODE* PNS_LINE_PLACER::CurrentNode( bool aLoopsRemoved ) const
|
||||||
|
|
||||||
void PNS_LINE_PLACER::splitAdjacentSegments( PNS_NODE* aNode, PNS_ITEM* aSeg, const VECTOR2I& aP )
|
void PNS_LINE_PLACER::splitAdjacentSegments( PNS_NODE* aNode, PNS_ITEM* aSeg, const VECTOR2I& aP )
|
||||||
{
|
{
|
||||||
if( aSeg && aSeg->OfKind( PNS_ITEM::SEGMENT ) )
|
if( !aSeg )
|
||||||
{
|
return;
|
||||||
|
|
||||||
|
if( !aSeg->OfKind( PNS_ITEM::SEGMENT ) )
|
||||||
|
return;
|
||||||
|
|
||||||
PNS_JOINT* jt = aNode->FindJoint( aP, aSeg );
|
PNS_JOINT* jt = aNode->FindJoint( aP, aSeg );
|
||||||
|
|
||||||
if( jt && jt->LinkCount() >= 1 )
|
if( jt && jt->LinkCount() >= 1 )
|
||||||
|
@ -707,7 +710,6 @@ void PNS_LINE_PLACER::splitAdjacentSegments( PNS_NODE* aNode, PNS_ITEM* aSeg, co
|
||||||
aNode->Remove( s_old );
|
aNode->Remove( s_old );
|
||||||
aNode->Add( s_new[0], true );
|
aNode->Add( s_new[0], true );
|
||||||
aNode->Add( s_new[1], 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 ) ) ) {
|
else if( !m_startItem || ( m_startItem->OfKind( PNS_ITEM::VIA ) && m_startItem->Layers().Overlaps( aLayer ) ) ) {
|
||||||
m_currentLayer = aLayer;
|
m_currentLayer = aLayer;
|
||||||
m_splitSeg = false;
|
initPlacement ( );
|
||||||
initPlacement ( m_splitSeg );
|
|
||||||
Move ( m_currentEnd, NULL );
|
Move ( m_currentEnd, NULL );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -741,11 +742,6 @@ bool PNS_LINE_PLACER::Start( const VECTOR2I& aP, PNS_ITEM* aStartItem )
|
||||||
static int unknowNetIdx = 0; // -10000;
|
static int unknowNetIdx = 0; // -10000;
|
||||||
int net = -1;
|
int net = -1;
|
||||||
|
|
||||||
bool splitSeg = false;
|
|
||||||
|
|
||||||
if( Router()->SnappingEnabled() )
|
|
||||||
p = Router()->SnapToItem( aStartItem, aP, splitSeg );
|
|
||||||
|
|
||||||
if( !aStartItem || aStartItem->Net() < 0 )
|
if( !aStartItem || aStartItem->Net() < 0 )
|
||||||
net = unknowNetIdx--;
|
net = unknowNetIdx--;
|
||||||
else
|
else
|
||||||
|
@ -757,15 +753,14 @@ bool PNS_LINE_PLACER::Start( const VECTOR2I& aP, PNS_ITEM* aStartItem )
|
||||||
m_startItem = aStartItem;
|
m_startItem = aStartItem;
|
||||||
m_placingVia = false;
|
m_placingVia = false;
|
||||||
m_chainedPlacement = false;
|
m_chainedPlacement = false;
|
||||||
m_splitSeg = splitSeg;
|
|
||||||
|
|
||||||
setInitialDirection( Settings().InitialDirection() );
|
setInitialDirection( Settings().InitialDirection() );
|
||||||
|
|
||||||
initPlacement( m_splitSeg );
|
initPlacement( );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PNS_LINE_PLACER::initPlacement( bool aSplitSeg )
|
void PNS_LINE_PLACER::initPlacement( )
|
||||||
{
|
{
|
||||||
m_idle = false;
|
m_idle = false;
|
||||||
|
|
||||||
|
@ -788,7 +783,6 @@ void PNS_LINE_PLACER::initPlacement( bool aSplitSeg )
|
||||||
world->KillChildren();
|
world->KillChildren();
|
||||||
PNS_NODE* rootNode = world->Branch();
|
PNS_NODE* rootNode = world->Branch();
|
||||||
|
|
||||||
if( aSplitSeg )
|
|
||||||
splitAdjacentSegments( rootNode, m_startItem, m_currentStart );
|
splitAdjacentSegments( rootNode, m_startItem, m_currentStart );
|
||||||
|
|
||||||
setWorld( rootNode );
|
setWorld( rootNode );
|
||||||
|
@ -927,7 +921,6 @@ bool PNS_LINE_PLACER::FixRoute( const VECTOR2I& aP, PNS_ITEM* aEndItem )
|
||||||
m_startItem = NULL;
|
m_startItem = NULL;
|
||||||
m_placingVia = false;
|
m_placingVia = false;
|
||||||
m_chainedPlacement = !pl.EndsWithVia();
|
m_chainedPlacement = !pl.EndsWithVia();
|
||||||
m_splitSeg = false;
|
|
||||||
initPlacement();
|
initPlacement();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1015,7 +1008,7 @@ void PNS_LINE_PLACER::UpdateSizes( const PNS_SIZES_SETTINGS& aSizes )
|
||||||
|
|
||||||
if( !m_idle )
|
if( !m_idle )
|
||||||
{
|
{
|
||||||
initPlacement( m_splitSeg );
|
initPlacement( );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,7 @@ private:
|
||||||
*
|
*
|
||||||
* Initializes placement of a new line with given parameters.
|
* Initializes placement of a new line with given parameters.
|
||||||
*/
|
*/
|
||||||
void initPlacement( bool aSplitSeg = false );
|
void initPlacement( );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function setInitialDirection()
|
* Function setInitialDirection()
|
||||||
|
@ -390,7 +390,6 @@ private:
|
||||||
|
|
||||||
bool m_idle;
|
bool m_idle;
|
||||||
bool m_chainedPlacement;
|
bool m_chainedPlacement;
|
||||||
bool m_splitSeg;
|
|
||||||
bool m_orthoMode;
|
bool m_orthoMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -83,8 +83,6 @@ PNS_ROUTER::PNS_ROUTER()
|
||||||
m_view = NULL;
|
m_view = NULL;
|
||||||
m_snappingEnabled = false;
|
m_snappingEnabled = false;
|
||||||
m_violation = 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<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
|
|
||||||
{
|
|
||||||
// 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 )
|
bool PNS_ROUTER::StartDragging( const VECTOR2I& aP, PNS_ITEM* aStartItem )
|
||||||
{
|
{
|
||||||
if( !aStartItem || aStartItem->OfKind( PNS_ITEM::SOLID ) )
|
if( !aStartItem || aStartItem->OfKind( PNS_ITEM::SOLID ) )
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
#include "pns_itemset.h"
|
#include "pns_itemset.h"
|
||||||
#include "pns_node.h"
|
#include "pns_node.h"
|
||||||
|
|
||||||
class GRID_HELPER;
|
|
||||||
class PNS_DEBUG_DECORATOR;
|
class PNS_DEBUG_DECORATOR;
|
||||||
class PNS_NODE;
|
class PNS_NODE;
|
||||||
class PNS_DIFF_PAIR_PLACER;
|
class PNS_DIFF_PAIR_PLACER;
|
||||||
|
@ -214,11 +213,6 @@ public:
|
||||||
|
|
||||||
PNS_PLACEMENT_ALGO *Placer() { return m_placer; }
|
PNS_PLACEMENT_ALGO *Placer() { return m_placer; }
|
||||||
|
|
||||||
void SetGrid( GRID_HELPER *aGridHelper )
|
|
||||||
{
|
|
||||||
m_gridHelper = aGridHelper;
|
|
||||||
}
|
|
||||||
|
|
||||||
PNS_ROUTER_IFACE *GetInterface() const
|
PNS_ROUTER_IFACE *GetInterface() const
|
||||||
{
|
{
|
||||||
return m_iface;
|
return m_iface;
|
||||||
|
@ -276,8 +270,6 @@ private:
|
||||||
|
|
||||||
wxString m_toolStatusbarName;
|
wxString m_toolStatusbarName;
|
||||||
wxString m_failureReason;
|
wxString m_failureReason;
|
||||||
|
|
||||||
GRID_HELPER *m_gridHelper;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -48,6 +48,8 @@ using namespace std::placeholders;
|
||||||
#include "pns_kicad_iface.h"
|
#include "pns_kicad_iface.h"
|
||||||
#include "pns_tool_base.h"
|
#include "pns_tool_base.h"
|
||||||
#include "pns_segment.h"
|
#include "pns_segment.h"
|
||||||
|
#include "pns_solid.h"
|
||||||
|
#include "pns_via.h"
|
||||||
#include "pns_router.h"
|
#include "pns_router.h"
|
||||||
#include "pns_meander_placer.h" // fixme: move settings to separate header
|
#include "pns_meander_placer.h" // fixme: move settings to separate header
|
||||||
#include "pns_tune_status_popup.h"
|
#include "pns_tune_status_popup.h"
|
||||||
|
@ -114,7 +116,6 @@ void PNS_TOOL_BASE::Reset( RESET_REASON aReason )
|
||||||
m_router->UpdateSizes( m_savedSizes );
|
m_router->UpdateSizes( m_savedSizes );
|
||||||
|
|
||||||
m_gridHelper = new GRID_HELPER( m_frame );
|
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 )
|
if( startItem && startItem->Net() >= 0 )
|
||||||
{
|
{
|
||||||
bool dummy;
|
bool dummy;
|
||||||
VECTOR2I psnap = m_router->SnapToItem( startItem, p, dummy );
|
VECTOR2I psnap = snapToItem( startItem, p, dummy );
|
||||||
|
|
||||||
if( snapEnabled )
|
if( snapEnabled )
|
||||||
{
|
{
|
||||||
|
@ -290,7 +291,7 @@ void PNS_TOOL_BASE::updateEndItem( TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
if( endItem )
|
if( endItem )
|
||||||
{
|
{
|
||||||
VECTOR2I cursorPos = m_router->SnapToItem( endItem, p, dummy );
|
VECTOR2I cursorPos = snapToItem( endItem, p, dummy );
|
||||||
m_ctls->ForceCursorPosition( true, cursorPos );
|
m_ctls->ForceCursorPosition( true, cursorPos );
|
||||||
m_endItem = endItem;
|
m_endItem = endItem;
|
||||||
m_endSnapPoint = cursorPos;
|
m_endSnapPoint = cursorPos;
|
||||||
|
@ -333,3 +334,56 @@ PNS_ROUTER *PNS_TOOL_BASE::Router() const
|
||||||
{
|
{
|
||||||
return m_router;
|
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<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;
|
||||||
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ public:
|
||||||
|
|
||||||
protected:
|
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 PNS_ITEM* pickSingleItem( const VECTOR2I& aWhere, int aNet = -1, int aLayer = -1 );
|
||||||
virtual void highlightNet( bool aEnabled, int aNetcode = -1 );
|
virtual void highlightNet( bool aEnabled, int aNetcode = -1 );
|
||||||
virtual void updateStartItem( TOOL_EVENT& aEvent );
|
virtual void updateStartItem( TOOL_EVENT& aEvent );
|
||||||
|
@ -77,8 +78,6 @@ protected:
|
||||||
GRID_HELPER* m_gridHelper;
|
GRID_HELPER* m_gridHelper;
|
||||||
PNS_KICAD_IFACE *m_iface;
|
PNS_KICAD_IFACE *m_iface;
|
||||||
PNS_ROUTER *m_router;
|
PNS_ROUTER *m_router;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue