use unique_ptr at client <-> pns-router border, to document the pns router is taking ownership

add overloads for NODE::Add( ... ) taking pointers to specific item types (retain old private add-Functions, they will come in handy later)
LINE overloads now take by reference, to document their special treatment.
updated code throughout affected by these changes
This commit is contained in:
decimad 2016-08-30 17:28:35 +02:00 committed by Maciej Suminski
parent 2aef1a4568
commit 96a3145543
15 changed files with 195 additions and 121 deletions

View File

@ -778,8 +778,8 @@ bool DIFF_PAIR_PLACER::FixRoute( const VECTOR2I& aP, ITEM* aEndItem )
if( m_currentTrace.EndsWithVias() ) if( m_currentTrace.EndsWithVias() )
{ {
m_lastNode->Add( m_currentTrace.PLine().Via().Clone() ); m_lastNode->Add( Clone( m_currentTrace.PLine().Via() ) );
m_lastNode->Add( m_currentTrace.NLine().Via().Clone() ); m_lastNode->Add( Clone( m_currentTrace.NLine().Via() ) );
m_chainedPlacement = false; m_chainedPlacement = false;
} }
else else
@ -790,8 +790,8 @@ bool DIFF_PAIR_PLACER::FixRoute( const VECTOR2I& aP, ITEM* aEndItem )
LINE lineP( m_currentTrace.PLine() ); LINE lineP( m_currentTrace.PLine() );
LINE lineN( m_currentTrace.NLine() ); LINE lineN( m_currentTrace.NLine() );
m_lastNode->Add( &lineP ); m_lastNode->Add( lineP );
m_lastNode->Add( &lineN ); m_lastNode->Add( lineN );
topo.SimplifyLine( &lineP ); topo.SimplifyLine( &lineP );
topo.SimplifyLine( &lineN ); topo.SimplifyLine( &lineN );

View File

@ -307,8 +307,8 @@ bool DP_MEANDER_PLACER::FixRoute( const VECTOR2I& aP, ITEM* aEndItem )
LINE lP( m_originPair.PLine(), m_finalShapeP ); LINE lP( m_originPair.PLine(), m_finalShapeP );
LINE lN( m_originPair.NLine(), m_finalShapeN ); LINE lN( m_originPair.NLine(), m_finalShapeN );
m_currentNode->Add( &lP ); m_currentNode->Add( lP );
m_currentNode->Add( &lN ); m_currentNode->Add( lN );
Router()->CommitRouting( m_currentNode ); Router()->CommitRouting( m_currentNode );

View File

@ -158,7 +158,7 @@ bool DRAGGER::dragMarkObstacles( const VECTOR2I& aP )
m_lastValidDraggedLine.ClearSegmentLinks(); m_lastValidDraggedLine.ClearSegmentLinks();
m_lastValidDraggedLine.Unmark(); m_lastValidDraggedLine.Unmark();
m_lastNode->Add( &m_lastValidDraggedLine ); m_lastNode->Add( m_lastValidDraggedLine );
m_draggedItems.Clear(); m_draggedItems.Clear();
m_draggedItems.Add( m_lastValidDraggedLine ); m_draggedItems.Add( m_lastValidDraggedLine );
@ -188,13 +188,15 @@ void DRAGGER::dumbDragVia( VIA* aVia, NODE* aNode, const VECTOR2I& aP )
m_draggedItems.Clear(); m_draggedItems.Clear();
// fixme: this is awful. // fixme: this is awful.
m_draggedVia = aVia->Clone(); auto via_clone = Clone( *aVia );
m_draggedVia = via_clone.get();
m_draggedVia->SetPos( aP ); m_draggedVia->SetPos( aP );
m_draggedItems.Add( m_draggedVia ); m_draggedItems.Add( m_draggedVia );
m_lastNode->Remove( aVia ); m_lastNode->Remove( aVia );
m_lastNode->Add( m_draggedVia ); m_lastNode->Add( std::move( via_clone ) );
for( ITEM* item : m_origViaConnections.Items() ) for( ITEM* item : m_origViaConnections.Items() )
{ {
@ -209,7 +211,7 @@ void DRAGGER::dumbDragVia( VIA* aVia, NODE* aNode, const VECTOR2I& aP )
m_draggedItems.Add( draggedLine ); m_draggedItems.Add( draggedLine );
m_lastNode->Remove( &origLine ); m_lastNode->Remove( &origLine );
m_lastNode->Add( &draggedLine ); m_lastNode->Add( draggedLine );
} }
} }
} }
@ -255,7 +257,7 @@ bool DRAGGER::dragShove( const VECTOR2I& aP )
m_lastValidDraggedLine.ClearSegmentLinks(); m_lastValidDraggedLine.ClearSegmentLinks();
m_lastValidDraggedLine.Unmark(); m_lastValidDraggedLine.Unmark();
m_lastNode->Add( &m_lastValidDraggedLine ); m_lastNode->Add( m_lastValidDraggedLine );
m_draggedItems.Clear(); m_draggedItems.Clear();
m_draggedItems.Add( m_lastValidDraggedLine ); m_draggedItems.Add( m_lastValidDraggedLine );

View File

@ -22,6 +22,7 @@
#ifndef __PNS_ITEM_H #ifndef __PNS_ITEM_H
#define __PNS_ITEM_H #define __PNS_ITEM_H
#include <memory>
#include <math/vector2d.h> #include <math/vector2d.h>
#include <geometry/shape.h> #include <geometry/shape.h>
@ -354,6 +355,21 @@ protected:
int m_rank; int m_rank;
}; };
template< typename T, typename S >
std::unique_ptr< T > ItemCast( std::unique_ptr< S > aPtr )
{
static_assert(std::is_base_of< ITEM, S >::value, "Need to be handed a ITEM!");
static_assert(std::is_base_of< ITEM, T >::value, "Need to cast to an ITEM!");
return std::unique_ptr< T >( static_cast<T*>(aPtr.release()) );
}
template< typename T >
std::unique_ptr< typename std::remove_const< T >::type > Clone( const T& aItem )
{
static_assert(std::is_base_of< ITEM, T >::value, "Need to be handed an ITEM!");
return std::unique_ptr< typename std::remove_const< T >::type >( aItem.Clone() );
}
} }
#endif // __PNS_ITEM_H #endif // __PNS_ITEM_H

View File

@ -429,7 +429,7 @@ PNS_KICAD_IFACE::~PNS_KICAD_IFACE()
} }
PNS::ITEM* PNS_KICAD_IFACE::syncPad( D_PAD* aPad ) std::unique_ptr< PNS::SOLID > PNS_KICAD_IFACE::syncPad( D_PAD* aPad )
{ {
LAYER_RANGE layers( 0, MAX_CU_LAYERS - 1 ); LAYER_RANGE layers( 0, MAX_CU_LAYERS - 1 );
@ -472,7 +472,7 @@ PNS::ITEM* PNS_KICAD_IFACE::syncPad( D_PAD* aPad )
return NULL; return NULL;
} }
PNS::SOLID* solid = new PNS::SOLID; std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID );
solid->SetLayers( layers ); solid->SetLayers( layers );
solid->SetNet( aPad->GetNetCode() ); solid->SetNet( aPad->GetNetCode() );
@ -564,8 +564,7 @@ PNS::ITEM* PNS_KICAD_IFACE::syncPad( D_PAD* aPad )
default: default:
wxLogTrace( "PNS", "unsupported pad shape" ); wxLogTrace( "PNS", "unsupported pad shape" );
delete solid; return nullptr;
return NULL;
} }
} }
else else
@ -661,9 +660,7 @@ PNS::ITEM* PNS_KICAD_IFACE::syncPad( D_PAD* aPad )
default: default:
wxLogTrace( "PNS", "unsupported pad shape" ); wxLogTrace( "PNS", "unsupported pad shape" );
delete solid; return nullptr;
return NULL;
} }
} }
} }
@ -671,33 +668,44 @@ PNS::ITEM* PNS_KICAD_IFACE::syncPad( D_PAD* aPad )
} }
PNS::ITEM* PNS_KICAD_IFACE::syncTrack( TRACK* aTrack ) std::unique_ptr< PNS::SEGMENT > PNS_KICAD_IFACE::syncTrack( TRACK* aTrack )
{ {
PNS::SEGMENT* s = std::unique_ptr< PNS::SEGMENT > segment(
new PNS::SEGMENT( SEG( aTrack->GetStart(), aTrack->GetEnd() ), aTrack->GetNetCode() ); new PNS::SEGMENT( SEG( aTrack->GetStart(), aTrack->GetEnd() ), aTrack->GetNetCode() )
);
s->SetWidth( aTrack->GetWidth() ); segment->SetWidth( aTrack->GetWidth() );
s->SetLayers( LAYER_RANGE( aTrack->GetLayer() ) ); segment->SetLayers( LAYER_RANGE( aTrack->GetLayer() ) );
s->SetParent( aTrack ); segment->SetParent( aTrack );
return s;
if( aTrack->IsLocked() ) {
segment->Mark( PNS::MK_LOCKED );
}
return segment;
} }
PNS::ITEM* PNS_KICAD_IFACE::syncVia( VIA* aVia ) std::unique_ptr< PNS::VIA > PNS_KICAD_IFACE::syncVia( VIA* aVia )
{ {
LAYER_ID top, bottom; LAYER_ID top, bottom;
aVia->LayerPair( &top, &bottom ); aVia->LayerPair( &top, &bottom );
PNS::VIA* v = new PNS::VIA( std::unique_ptr<PNS::VIA> via( new PNS::VIA(
aVia->GetPosition(), aVia->GetPosition(),
LAYER_RANGE( top, bottom ), LAYER_RANGE( top, bottom ),
aVia->GetWidth(), aVia->GetWidth(),
aVia->GetDrillValue(), aVia->GetDrillValue(),
aVia->GetNetCode(), aVia->GetNetCode(),
aVia->GetViaType() ); aVia->GetViaType() )
);
v->SetParent( aVia ); via->SetParent( aVia );
return v; if( aVia->IsLocked() ) {
via->Mark( PNS::MK_LOCKED );
}
return via;
} }
@ -720,10 +728,10 @@ void PNS_KICAD_IFACE::SyncWorld( PNS::NODE *aWorld )
{ {
for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() ) for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() )
{ {
PNS::ITEM* solid = syncPad( pad ); std::unique_ptr< PNS::SOLID > solid = syncPad( pad );
if( solid ) if( solid )
aWorld->Add( solid ); aWorld->Add( std::move( solid ) );
} }
} }
@ -732,16 +740,17 @@ void PNS_KICAD_IFACE::SyncWorld( PNS::NODE *aWorld )
KICAD_T type = t->Type(); KICAD_T type = t->Type();
PNS::ITEM* item = NULL; PNS::ITEM* item = NULL;
if( type == PCB_TRACE_T ) if( type == PCB_TRACE_T ) {
item = syncTrack( t ); std::unique_ptr< PNS::SEGMENT > segment = syncTrack( t );
else if( type == PCB_VIA_T ) if( segment ) {
item = syncVia( static_cast<VIA*>( t ) ); aWorld->Add( std::move( segment ) );
}
if( t->IsLocked() ) } else if( type == PCB_VIA_T ) {
item->Mark( PNS::MK_LOCKED ); std::unique_ptr< PNS::VIA > via = syncVia( static_cast<VIA*>( t ) );
if( via ) {
if( item ) aWorld->Add( std::move( via ) );
aWorld->Add( item ); }
}
} }
int worstClearance = m_board->GetDesignSettings().GetBiggestClearanceValue(); int worstClearance = m_board->GetDesignSettings().GetBiggestClearanceValue();

View File

@ -62,9 +62,9 @@ private:
PNS_PCBNEW_RULE_RESOLVER* m_ruleResolver; PNS_PCBNEW_RULE_RESOLVER* m_ruleResolver;
PNS_PCBNEW_DEBUG_DECORATOR* m_debugDecorator; PNS_PCBNEW_DEBUG_DECORATOR* m_debugDecorator;
PNS::ITEM* syncPad( D_PAD* aPad ); std::unique_ptr< PNS::SOLID > syncPad( D_PAD* aPad );
PNS::ITEM* syncTrack( TRACK* aTrack ); std::unique_ptr< PNS::SEGMENT > syncTrack( TRACK* aTrack );
PNS::ITEM* syncVia( VIA* aVia ); std::unique_ptr< PNS::VIA > syncVia( VIA* aVia );
KIGFX::VIEW* m_view; KIGFX::VIEW* m_view;
KIGFX::VIEW_GROUP* m_previewItems; KIGFX::VIEW_GROUP* m_previewItems;

View File

@ -697,17 +697,18 @@ void LINE_PLACER::splitAdjacentSegments( NODE* aNode, ITEM* aSeg, const VECTOR2I
return; return;
SEGMENT* s_old = static_cast<SEGMENT*>( aSeg ); SEGMENT* s_old = static_cast<SEGMENT*>( aSeg );
SEGMENT* s_new[2];
std::unique_ptr< SEGMENT > s_new[2] = {
s_new[0] = s_old->Clone(); Clone( *s_old ),
s_new[1] = s_old->Clone(); Clone( *s_old )
};
s_new[0]->SetEnds( s_old->Seg().A, aP ); s_new[0]->SetEnds( s_old->Seg().A, aP );
s_new[1]->SetEnds( aP, s_old->Seg().B ); s_new[1]->SetEnds( aP, s_old->Seg().B );
aNode->Remove( s_old ); aNode->Remove( s_old );
aNode->Add( s_new[0], true ); aNode->Add( std::move( s_new[0] ), true );
aNode->Add( s_new[1], true ); aNode->Add( std::move( s_new[1] ), true );
} }
@ -861,7 +862,7 @@ bool LINE_PLACER::FixRoute( const VECTOR2I& aP, ITEM* aEndItem )
{ {
if( pl.EndsWithVia() ) if( pl.EndsWithVia() )
{ {
m_lastNode->Add( pl.Via().Clone() ); m_lastNode->Add( Clone( pl.Via() ) );
Router()->CommitRouting( m_lastNode ); Router()->CommitRouting( m_lastNode );
m_lastNode = NULL; m_lastNode = NULL;
@ -893,15 +894,15 @@ bool LINE_PLACER::FixRoute( const VECTOR2I& aP, ITEM* aEndItem )
for( int i = 0; i < lastV; i++ ) for( int i = 0; i < lastV; i++ )
{ {
const SEG& s = pl.CSegment( i ); const SEG& s = pl.CSegment( i );
SEGMENT* seg = new SEGMENT( s, m_currentNet ); std::unique_ptr< SEGMENT > seg( new SEGMENT( s, m_currentNet ) );
seg->SetWidth( pl.Width() ); seg->SetWidth( pl.Width() );
seg->SetLayer( m_currentLayer ); seg->SetLayer( m_currentLayer );
m_lastNode->Add( seg ); lastSeg = seg.get();
lastSeg = seg; m_lastNode->Add( std::move( seg ) );
} }
if( pl.EndsWithVia() ) if( pl.EndsWithVia() )
m_lastNode->Add( pl.Via().Clone() ); m_lastNode->Add( Clone( pl.Via() ) );
if( realEnd ) if( realEnd )
simplifyNewLine( m_lastNode, lastSeg ); simplifyNewLine( m_lastNode, lastSeg );
@ -938,7 +939,7 @@ void LINE_PLACER::removeLoops( NODE* aNode, LINE& aLatest )
return; return;
std::set<SEGMENT *> toErase; std::set<SEGMENT *> toErase;
aNode->Add( &aLatest, true ); aNode->Add( aLatest, true );
for( int s = 0; s < aLatest.LinkCount(); s++ ) for( int s = 0; s < aLatest.LinkCount(); s++ )
{ {
@ -994,7 +995,7 @@ void LINE_PLACER::simplifyNewLine( NODE* aNode, SEGMENT* aLatest )
LINE lnew( l ); LINE lnew( l );
aNode->Remove( &l ); aNode->Remove( &l );
lnew.SetShape( simplified ); lnew.SetShape( simplified );
aNode->Add( &lnew ); aNode->Add( lnew );
} }
} }

View File

@ -194,7 +194,7 @@ bool MEANDER_PLACER::FixRoute( const VECTOR2I& aP, ITEM* aEndItem )
return false; return false;
m_currentTrace = LINE( m_originLine, m_finalShape ); m_currentTrace = LINE( m_originLine, m_finalShape );
m_currentNode->Add( &m_currentTrace ); m_currentNode->Add( m_currentTrace );
Router()->CommitRouting( m_currentNode ); Router()->CommitRouting( m_currentNode );
return true; return true;

View File

@ -535,6 +535,11 @@ void NODE::addSolid( SOLID* aSolid )
m_index->Add( aSolid ); m_index->Add( aSolid );
} }
void NODE::Add( std::unique_ptr< SOLID > aSolid )
{
aSolid->SetOwner( this );
addSolid( aSolid.release() );
}
void NODE::addVia( VIA* aVia ) void NODE::addVia( VIA* aVia )
{ {
@ -542,10 +547,15 @@ void NODE::addVia( VIA* aVia )
m_index->Add( aVia ); m_index->Add( aVia );
} }
void NODE::Add( std::unique_ptr< VIA > aVia )
void NODE::addLine( LINE* aLine, bool aAllowRedundant )
{ {
SHAPE_LINE_CHAIN& l = aLine->Line(); aVia->SetOwner( this );
addVia( aVia.release() );
}
void NODE::addLine( LINE& aLine, bool aAllowRedundant )
{
SHAPE_LINE_CHAIN& l = aLine.Line();
for( int i = 0; i < l.SegmentCount(); i++ ) for( int i = 0; i < l.SegmentCount(); i++ )
{ {
@ -553,7 +563,7 @@ void NODE::addLine( LINE* aLine, bool aAllowRedundant )
if( s.A != s.B ) if( s.A != s.B )
{ {
SEGMENT* pseg = new SEGMENT( *aLine, s ); SEGMENT* pseg = new SEGMENT( aLine, s );
SEGMENT* psegR = NULL; SEGMENT* psegR = NULL;
if( !aAllowRedundant ) if( !aAllowRedundant )
@ -561,7 +571,7 @@ void NODE::addLine( LINE* aLine, bool aAllowRedundant )
if( psegR ) if( psegR )
{ {
aLine->LinkSegment( psegR ); aLine.LinkSegment( psegR );
delete pseg; delete pseg;
} }
@ -569,10 +579,10 @@ void NODE::addLine( LINE* aLine, bool aAllowRedundant )
{ {
pseg->SetOwner( this ); pseg->SetOwner( this );
linkJoint( s.A, pseg->Layers(), aLine->Net(), pseg ); linkJoint( s.A, pseg->Layers(), aLine.Net(), pseg );
linkJoint( s.B, pseg->Layers(), aLine->Net(), pseg ); linkJoint( s.B, pseg->Layers(), aLine.Net(), pseg );
aLine->LinkSegment( pseg ); aLine.LinkSegment( pseg );
m_index->Add( pseg ); m_index->Add( pseg );
} }
@ -580,47 +590,52 @@ void NODE::addLine( LINE* aLine, bool aAllowRedundant )
} }
} }
void NODE::Add( LINE& aLine, bool aAllowRedundant )
void NODE::addSegment( SEGMENT* aSeg, bool aAllowRedundant )
{ {
if( aSeg->Seg().A == aSeg->Seg().B ) addLine( aLine, aAllowRedundant );
{ }
wxLogTrace( "PNS", "attempting to add a segment with same end coordinates, ignoring." );
return;
}
if( !aAllowRedundant && findRedundantSegment( aSeg ) )
return;
aSeg->SetOwner( this );
void NODE::addSegment( SEGMENT* aSeg )
{
linkJoint( aSeg->Seg().A, aSeg->Layers(), aSeg->Net(), aSeg ); linkJoint( aSeg->Seg().A, aSeg->Layers(), aSeg->Net(), aSeg );
linkJoint( aSeg->Seg().B, aSeg->Layers(), aSeg->Net(), aSeg ); linkJoint( aSeg->Seg().B, aSeg->Layers(), aSeg->Net(), aSeg );
m_index->Add( aSeg ); m_index->Add( aSeg );
} }
void NODE::Add( std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant )
void NODE::Add( ITEM* aItem, bool aAllowRedundant )
{ {
aItem->SetOwner( this ); if( aSegment->Seg().A == aSegment->Seg().B )
{
wxLogTrace( "PNS", "attempting to add a segment with same end coordinates, ignoring." );
return;
}
if( !aAllowRedundant && findRedundantSegment( aSegment.get() ) )
return;
aSegment->SetOwner( this );
addSegment( aSegment.release() );
}
void NODE::Add( std::unique_ptr< ITEM > aItem, bool aAllowRedundant )
{
switch( aItem->Kind() ) switch( aItem->Kind() )
{ {
case ITEM::SOLID_T: case ITEM::SOLID_T:
addSolid( static_cast<SOLID*>( aItem ) ); Add( ItemCast<SOLID>( std::move( aItem ) ) );
break; break;
case ITEM::SEGMENT_T: case ITEM::SEGMENT_T:
addSegment( static_cast<SEGMENT*>( aItem ), aAllowRedundant ); Add( ItemCast<SEGMENT>( std::move( aItem ) ), aAllowRedundant );
break; break;
case ITEM::LINE_T: case ITEM::LINE_T:
addLine( static_cast<LINE*>( aItem ), aAllowRedundant ); assert( false );
break; break;
case ITEM::VIA_T: case ITEM::VIA_T:
addVia( static_cast<VIA*>( aItem ) ); Add( ItemCast<VIA>( std::move( aItem ) ) );
break; break;
default: default:
@ -719,12 +734,17 @@ void NODE::removeVia( VIA* aVia )
} }
void NODE::Replace( ITEM* aOldItem, ITEM* aNewItem ) void NODE::Replace( ITEM* aOldItem, std::unique_ptr< ITEM > aNewItem )
{ {
Remove( aOldItem ); Remove( aOldItem );
Add( aNewItem ); Add( std::move( aNewItem ) );
} }
void NODE::Replace( LINE& aOldLine, LINE& aNewLine )
{
Remove( aOldLine );
Add( aNewLine );
}
void NODE::Remove( ITEM* aItem ) void NODE::Remove( ITEM* aItem )
{ {
@ -1184,7 +1204,7 @@ void NODE::Commit( NODE* aNode )
{ {
(*i)->SetRank( -1 ); (*i)->SetRank( -1 );
(*i)->Unmark(); (*i)->Unmark();
Add( *i ); Add( std::unique_ptr<ITEM>( *i ) );
} }
releaseChildren(); releaseChildren();

View File

@ -273,8 +273,16 @@ public:
* @param aAllowRedundant if true, duplicate items are allowed (e.g. a segment or via * @param aAllowRedundant if true, duplicate items are allowed (e.g. a segment or via
* at the same coordinates as an existing one) * at the same coordinates as an existing one)
*/ */
void Add( ITEM* aItem, bool aAllowRedundant = false ); void Add( std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant = false );
void Add( std::unique_ptr< SOLID > aSolid );
void Add( std::unique_ptr< VIA > aVia );
void Add( LINE& aLine, bool aAllowRedundant = false );
private:
void Add( std::unique_ptr< ITEM > aItem, bool aAllowRedundant = false );
public:
/** /**
* Function Remove() * Function Remove()
* *
@ -298,7 +306,8 @@ public:
* @param aOldItem item to be removed * @param aOldItem item to be removed
* @param aNewItem item add instead * @param aNewItem item add instead
*/ */
void Replace( ITEM* aOldItem, ITEM* aNewItem ); void Replace( ITEM* aOldItem, std::unique_ptr< ITEM > aNewItem );
void Replace( LINE& aOldLine, LINE& aNewLine );
/** /**
* Function Branch() * Function Branch()
@ -429,8 +438,8 @@ private:
///> helpers for adding/removing items ///> helpers for adding/removing items
void addSolid( SOLID* aSeg ); void addSolid( SOLID* aSeg );
void addSegment( SEGMENT* aSeg, bool aAllowRedundant ); void addSegment( SEGMENT* aSeg );
void addLine( LINE* aLine, bool aAllowRedundant ); void addLine( LINE& aLine, bool aAllowRedundant );
void addVia( VIA* aVia ); void addVia( VIA* aVia );
void removeSolid( SOLID* aSeg ); void removeSolid( SOLID* aSeg );
void removeLine( LINE* aLine ); void removeLine( LINE* aLine );

View File

@ -45,7 +45,19 @@
namespace PNS { namespace PNS {
void SHOVE::replaceItems( ITEM* aOld, ITEM* aNew ) void SHOVE::replaceItems( ITEM* aOld, std::unique_ptr< ITEM > aNew )
{
OPT_BOX2I changed_area = ChangedArea( aOld, aNew.get() );
if( changed_area )
{
m_affectedAreaSum = m_affectedAreaSum ? m_affectedAreaSum->Merge( *changed_area ) : *changed_area;
}
m_currentNode->Replace( aOld, std::move( aNew ) );
}
void SHOVE::replaceLine( LINE& aOld, LINE& aNew )
{ {
OPT_BOX2I changed_area = ChangedArea( aOld, aNew ); OPT_BOX2I changed_area = ChangedArea( aOld, aNew );
@ -57,7 +69,6 @@ void SHOVE::replaceItems( ITEM* aOld, ITEM* aNew )
m_currentNode->Replace( aOld, aNew ); m_currentNode->Replace( aOld, aNew );
} }
int SHOVE::getClearance( const ITEM* aA, const ITEM* aB ) const int SHOVE::getClearance( const ITEM* aA, const ITEM* aB ) const
{ {
if( m_forceClearance >= 0 ) if( m_forceClearance >= 0 )
@ -349,7 +360,7 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingSegment( LINE& aCurrent, SEGMENT* aObstacl
shovedLine.SetRank( rank - 1 ); shovedLine.SetRank( rank - 1 );
sanityCheck( &obstacleLine, &shovedLine ); sanityCheck( &obstacleLine, &shovedLine );
replaceItems( &obstacleLine, &shovedLine ); replaceLine( obstacleLine, shovedLine );
if( !pushLine( shovedLine ) ) if( !pushLine( shovedLine ) )
rv = SH_INCOMPLETE; rv = SH_INCOMPLETE;
@ -383,7 +394,7 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingLine( LINE& aCurrent, LINE& aObstacle )
} }
sanityCheck( &aObstacle, &shovedLine ); sanityCheck( &aObstacle, &shovedLine );
replaceItems( &aObstacle, &shovedLine ); replaceLine( aObstacle, shovedLine );
int rank = aObstacle.Rank(); int rank = aObstacle.Rank();
shovedLine.SetRank( rank - 1 ); shovedLine.SetRank( rank - 1 );
@ -508,7 +519,7 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingSolid( LINE& aCurrent, ITEM* aObstacle )
if(!success) if(!success)
return SH_INCOMPLETE; return SH_INCOMPLETE;
replaceItems( &aCurrent, &walkaroundLine ); replaceLine( aCurrent, walkaroundLine );
walkaroundLine.SetRank( nextRank ); walkaroundLine.SetRank( nextRank );
#ifdef DEBUG #ifdef DEBUG
@ -607,13 +618,13 @@ SHOVE::SHOVE_STATUS SHOVE::pushVia( VIA* aVia, const VECTOR2I& aForce, int aCurr
p0_pushed += aForce.Resize( 2 ); // make sure pushed via does not overlap with any existing joint p0_pushed += aForce.Resize( 2 ); // make sure pushed via does not overlap with any existing joint
} }
VIA* pushedVia = aVia->Clone(); std::unique_ptr< VIA > pushedVia = Clone( *aVia );
pushedVia->SetPos( p0_pushed ); pushedVia->SetPos( p0_pushed );
pushedVia->Mark( aVia->Marker() ); pushedVia->Mark( aVia->Marker() );
if( aVia->Marker() & MK_HEAD ) if( aVia->Marker() & MK_HEAD )
{ {
m_draggedVia = pushedVia; m_draggedVia = pushedVia.get();
m_draggedViaHeadSet.Clear(); m_draggedViaHeadSet.Clear();
} }
@ -645,19 +656,19 @@ SHOVE::SHOVE_STATUS SHOVE::pushVia( VIA* aVia, const VECTOR2I& aForce, int aCurr
} }
} }
m_draggedViaHeadSet.Add( pushedVia ); m_draggedViaHeadSet.Add( pushedVia.get() );
if( aDryRun ) if( aDryRun )
return SH_OK; return SH_OK;
replaceItems( aVia, pushedVia );
#ifdef DEBUG #ifdef DEBUG
m_logger.Log( aVia, 0, "obstacle-via" ); m_logger.Log( aVia, 0, "obstacle-via" );
#endif #endif
pushedVia->SetRank( aCurrentRank - 1 ); pushedVia->SetRank( aCurrentRank - 1 );
replaceItems( aVia, std::move( pushedVia ) );
#ifdef DEBUG #ifdef DEBUG
m_logger.Log( pushedVia, 1, "pushed-via" ); m_logger.Log( pushedVia, 1, "pushed-via" );
#endif #endif
@ -678,7 +689,7 @@ SHOVE::SHOVE_STATUS SHOVE::pushVia( VIA* aVia, const VECTOR2I& aForce, int aCurr
if( lp.second.SegmentCount() ) if( lp.second.SegmentCount() )
{ {
replaceItems( &lp.first, &lp.second ); replaceLine( lp.first, lp.second );
lp.second.SetRank( aCurrentRank - 1 ); lp.second.SetRank( aCurrentRank - 1 );
if( !pushLine( lp.second, true ) ) if( !pushLine( lp.second, true ) )
@ -820,7 +831,7 @@ SHOVE::SHOVE_STATUS SHOVE::onReverseCollidingVia( LINE& aCurrent, VIA* aObstacle
m_logger.Log( &shoved, 3, "shoved-line" ); m_logger.Log( &shoved, 3, "shoved-line" );
#endif #endif
int currentRank = aCurrent.Rank(); int currentRank = aCurrent.Rank();
replaceItems( &aCurrent, &shoved ); replaceLine( aCurrent, shoved );
if( !pushLine( shoved ) ) if( !pushLine( shoved ) )
return SH_INCOMPLETE; return SH_INCOMPLETE;
@ -1092,7 +1103,7 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveLines( const LINE& aCurrentHead )
m_currentNode = parent->Branch(); m_currentNode = parent->Branch();
m_currentNode->ClearRanks(); m_currentNode->ClearRanks();
m_currentNode->Add( &head ); m_currentNode->Add( head );
m_currentNode->LockJoint( head.CPoint(0), &head, true ); m_currentNode->LockJoint( head.CPoint(0), &head, true );
@ -1105,15 +1116,13 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveLines( const LINE& aCurrentHead )
m_logger.NewGroup( "initial", 0 ); m_logger.NewGroup( "initial", 0 );
m_logger.Log( &head, 0, "head" ); m_logger.Log( &head, 0, "head" );
VIA* headVia = NULL;
if( head.EndsWithVia() ) if( head.EndsWithVia() )
{ {
headVia = head.Via().Clone(); std::unique_ptr< VIA >headVia = Clone( head.Via() );
m_currentNode->Add( headVia );
headVia->Mark( MK_HEAD ); headVia->Mark( MK_HEAD );
headVia->SetRank( 100000 ); headVia->SetRank( 100000 );
m_logger.Log( headVia, 0, "head-via" ); m_logger.Log( headVia.get(), 0, "head-via" );
m_currentNode->Add( std::move( headVia ) );
} }
if( !pushLine( head ) ) if( !pushLine( head ) )
@ -1204,7 +1213,7 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveMultiLines( const ITEM_SET& aHeadSet )
LINE head( *headOrig ); LINE head( *headOrig );
head.ClearSegmentLinks(); head.ClearSegmentLinks();
m_currentNode->Add( &head ); m_currentNode->Add( head );
head.Mark( MK_HEAD ); head.Mark( MK_HEAD );
head.SetRank( 100000 ); head.SetRank( 100000 );
@ -1217,11 +1226,11 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveMultiLines( const ITEM_SET& aHeadSet )
if( head.EndsWithVia() ) if( head.EndsWithVia() )
{ {
headVia = head.Via().Clone(); // fixme: leak std::unique_ptr< VIA > headVia = Clone( head.Via() );
m_currentNode->Add( headVia );
headVia->Mark( MK_HEAD ); headVia->Mark( MK_HEAD );
headVia->SetRank( 100000 ); headVia->SetRank( 100000 );
m_logger.Log( headVia, 0, "head-via" ); m_logger.Log( headVia.get(), 0, "head-via" );
m_currentNode->Add( std::move( headVia ) );
} }
} }
@ -1375,7 +1384,7 @@ void SHOVE::runOptimizer( NODE* aNode )
{ {
aNode->Remove( &line ); aNode->Remove( &line );
line.SetShape( optimized.CLine() ); line.SetShape( optimized.CLine() );
aNode->Add( &line ); aNode->Add( line );
} }
} }
} }

View File

@ -131,7 +131,8 @@ private:
LINE assembleLine( const SEGMENT* aSeg, int* aIndex = NULL ); LINE assembleLine( const SEGMENT* aSeg, int* aIndex = NULL );
void replaceItems( ITEM* aOld, ITEM* aNew ); void replaceItems( ITEM* aOld, std::unique_ptr< ITEM > aNew );
void replaceLine( LINE& aOld, LINE& aNew );
OPT_BOX2I m_affectedAreaSum; OPT_BOX2I m_affectedAreaSum;

View File

@ -50,7 +50,7 @@ bool TOPOLOGY::SimplifyLine( LINE* aLine )
LINE lnew( l ); LINE lnew( l );
m_world->Remove( &l ); m_world->Remove( &l );
lnew.SetShape( simplified ); lnew.SetShape( simplified );
m_world->Add( &lnew ); m_world->Add( lnew );
return true; return true;
} }
@ -102,7 +102,7 @@ bool TOPOLOGY::LeadingRatLine( const LINE* aTrack, SHAPE_LINE_CHAIN& aRatLine )
return false; return false;
std::unique_ptr<NODE> tmpNode( m_world->Branch() ); std::unique_ptr<NODE> tmpNode( m_world->Branch() );
tmpNode->Add( &track ); tmpNode->Add( track );
JOINT* jt = tmpNode->FindJoint( track.CPoint( -1 ), &track ); JOINT* jt = tmpNode->FindJoint( track.CPoint( -1 ), &track );

View File

@ -248,4 +248,9 @@ OPT_BOX2I ChangedArea( const ITEM* aItemA, const ITEM* aItemB )
return OPT_BOX2I(); return OPT_BOX2I();
} }
OPT_BOX2I ChangedArea( const LINE& aLineA, const LINE& aLineB )
{
return aLineA.ChangedArea( &aLineB );
}
} }

View File

@ -34,6 +34,7 @@ namespace PNS {
constexpr int HULL_MARGIN = 10; constexpr int HULL_MARGIN = 10;
class ITEM; class ITEM;
class LINE;
/** Various utility functions */ /** Various utility functions */
@ -55,14 +56,15 @@ const SHAPE_LINE_CHAIN ConvexHull( const SHAPE_CONVEX& convex, int aClearance );
SHAPE_RECT ApproximateSegmentAsRect( const SHAPE_SEGMENT& aSeg ); SHAPE_RECT ApproximateSegmentAsRect( const SHAPE_SEGMENT& aSeg );
#if 0 OPT_BOX2I ChangedArea( const ITEM* aItemA, const ITEM* aItemB );
OPT_BOX2I ChangedArea( const LINE& aLineA, const LINE& aLineB );
#if 0
void DrawDebugPoint( VECTOR2I aP, int aColor ); void DrawDebugPoint( VECTOR2I aP, int aColor );
void DrawDebugBox( BOX2I aB, int aColor ); void DrawDebugBox( BOX2I aB, int aColor );
void DrawDebugSeg( SEG aS, int aColor ); void DrawDebugSeg( SEG aS, int aColor );
void DrawDebugDirs( VECTOR2D aP, int aMask, int aColor ); void DrawDebugDirs( VECTOR2D aP, int aMask, int aColor );
#endif #endif
OPT_BOX2I ChangedArea( const ITEM* aItemA, const ITEM* aItemB );
} }