Tighten ownership model of PNS::ITEM.

In particular, ownership must be explicitly set.  It is
no longer inherited through copy/clone/etc.
This commit is contained in:
Jeff Young 2023-04-28 11:03:24 +01:00
parent d3311ee231
commit f8270b9cec
8 changed files with 29 additions and 46 deletions

View File

@ -39,7 +39,7 @@ HOLE::~HOLE()
HOLE* HOLE::Clone() const HOLE* HOLE::Clone() const
{ {
HOLE* h = new HOLE( nullptr, m_holeShape->Clone() ); HOLE* h = new HOLE( m_holeShape->Clone() );
h->SetLayers( Layers() ); h->SetLayers( Layers() );
h->SetOwner( nullptr ); h->SetOwner( nullptr );
@ -134,7 +134,7 @@ void HOLE::Move( const VECTOR2I& delta )
HOLE* HOLE::MakeCircularHole( const VECTOR2I& pos, int radius ) HOLE* HOLE::MakeCircularHole( const VECTOR2I& pos, int radius )
{ {
auto circle = new SHAPE_CIRCLE( pos, radius ); auto circle = new SHAPE_CIRCLE( pos, radius );
auto hole = new HOLE( nullptr, circle ); auto hole = new HOLE( circle );
hole->SetLayers( LAYER_RANGE( F_Cu, B_Cu ) ); hole->SetLayers( LAYER_RANGE( F_Cu, B_Cu ) );
return hole; return hole;
} }

View File

@ -33,14 +33,18 @@ namespace PNS
class HOLE : public ITEM class HOLE : public ITEM
{ {
public: public:
HOLE( ITEM* aParentPadVia, SHAPE* aShape ) : HOLE( SHAPE* aShape ) :
ITEM( ITEM::HOLE_T ), ITEM( ITEM::HOLE_T ),
m_holeShape( aShape ), m_holeShape( aShape ),
m_parentPadVia( aParentPadVia ) m_parentPadVia( nullptr )
{ {
} }
HOLE( const ITEM& aOther ) : ITEM( aOther ) {} HOLE( const ITEM& aOther ) :
ITEM( aOther ),
m_parentPadVia( nullptr )
{
}
virtual ~HOLE(); virtual ~HOLE();

View File

@ -128,7 +128,7 @@ public:
m_movable = aOther.m_movable; m_movable = aOther.m_movable;
m_kind = aOther.m_kind; m_kind = aOther.m_kind;
m_parent = aOther.m_parent; m_parent = aOther.m_parent;
m_owner = aOther.m_owner; // fixme: wtf this was null? m_owner = nullptr;
m_marker = aOther.m_marker; m_marker = aOther.m_marker;
m_rank = aOther.m_rank; m_rank = aOther.m_rank;
m_routable = aOther.m_routable; m_routable = aOther.m_routable;

View File

@ -231,7 +231,7 @@ public:
return m_tag.pos; return m_tag.pos;
} }
int Net() const int Net() const override
{ {
return m_tag.net; return m_tag.net;
} }

View File

@ -1098,12 +1098,7 @@ std::unique_ptr<PNS::SOLID> PNS_KICAD_IFACE_BASE::syncPad( PAD* aPad )
solid->SetOffset( VECTOR2I( offset.x, offset.y ) ); solid->SetOffset( VECTOR2I( offset.x, offset.y ) );
if( aPad->GetDrillSize().x > 0 ) if( aPad->GetDrillSize().x > 0 )
{ solid->SetHole( new PNS::HOLE( aPad->GetEffectiveHoleShape()->Clone() ) );
SHAPE_SEGMENT* slot = (SHAPE_SEGMENT*) aPad->GetEffectiveHoleShape()->Clone();
PNS::HOLE* hole = new PNS::HOLE( solid.get(), slot );
solid->SetHole( hole );
}
// We generate a single SOLID for a pad, so we have to treat it as ALWAYS_FLASHED and then // We generate a single SOLID for a pad, so we have to treat it as ALWAYS_FLASHED and then
// perform layer-specific flashing tests internally. // perform layer-specific flashing tests internally.
@ -1176,11 +1171,7 @@ std::unique_ptr<PNS::VIA> PNS_KICAD_IFACE_BASE::syncVia( PCB_VIA* aVia )
via->Mark( PNS::MK_LOCKED ); via->Mark( PNS::MK_LOCKED );
via->SetIsFree( aVia->GetIsFree() ); via->SetIsFree( aVia->GetIsFree() );
via->SetHole( PNS::HOLE::MakeCircularHole( aVia->GetPosition(), aVia->GetDrillValue() / 2 ) );
SHAPE* holeShape = new SHAPE_CIRCLE( aVia->GetPosition(), aVia->GetDrillValue() / 2 );
PNS::HOLE* viaHole = new PNS::HOLE( via.get(), holeShape );
via->SetHole( viaHole );
return via; return via;
} }

View File

@ -51,6 +51,7 @@ LINE::LINE( const LINE& aOther )
{ {
m_via = aOther.m_via->Clone(); m_via = aOther.m_via->Clone();
m_via->SetOwner( this ); m_via->SetOwner( this );
m_via->SetNet( m_net );
} }
m_marker = aOther.m_marker; m_marker = aOther.m_marker;
@ -82,6 +83,7 @@ LINE& LINE::operator=( const LINE& aOther )
{ {
m_via = aOther.m_via->Clone(); m_via = aOther.m_via->Clone();
m_via->SetOwner( this ); m_via->SetOwner( this );
m_via->SetNet( m_net );
} }
m_marker = aOther.m_marker; m_marker = aOther.m_marker;
@ -1267,11 +1269,7 @@ bool LINE::HasLockedSegments() const
void LINE::Clear() void LINE::Clear()
{ {
if( m_via && m_via->BelongsTo( this ) ) RemoveVia();
{
delete m_via;
m_via = nullptr;
}
m_line.Clear(); m_line.Clear();
} }

View File

@ -113,19 +113,14 @@ public:
virtual void SetHole( HOLE* aHole ) override virtual void SetHole( HOLE* aHole ) override
{ {
if( m_hole ) if( m_hole && m_hole->BelongsTo( this ) )
{ delete m_hole;
assert( m_hole->Owner() == nullptr );
}
m_hole = aHole; m_hole = aHole;
m_hole->SetNet( Net() ); m_hole->SetParentPadVia( this );
m_hole->SetOwner( this ); m_hole->SetOwner( this );
m_hole->SetLayers( m_layers ); // fixme: backdrill vias can have hole layer set different
if( m_hole ) // than copper layer set
{
m_hole->SetLayers( m_layers ); // fixme: backdrill vias can have hole layer set different than copper layer set
}
} }
virtual bool HasHole() const override { return m_hole != nullptr; } virtual bool HasHole() const override { return m_hole != nullptr; }

View File

@ -55,11 +55,11 @@ public:
m_hole( nullptr ) m_hole( nullptr )
{ {
m_diameter = 2; // Dummy value m_diameter = 2; // Dummy value
m_drill = 0; m_drill = 1; // Dummy value
m_viaType = VIATYPE::THROUGH; m_viaType = VIATYPE::THROUGH;
m_isFree = false; m_isFree = false;
m_isVirtual = false; m_isVirtual = false;
SetHole( HOLE::MakeCircularHole( m_pos, m_diameter / 2 ) ); SetHole( HOLE::MakeCircularHole( m_pos, m_drill / 2 ) );
} }
VIA( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aDiameter, int aDrill, VIA( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aDiameter, int aDrill,
@ -100,10 +100,8 @@ public:
virtual ~VIA() virtual ~VIA()
{ {
if ( m_hole && m_hole->BelongsTo( this ) ) if ( m_hole && m_hole->BelongsTo( this ) )
{
delete m_hole; delete m_hole;
} }
}
static inline bool ClassOf( const ITEM* aItem ) static inline bool ClassOf( const ITEM* aItem )
{ {
@ -116,6 +114,7 @@ public:
{ {
m_pos = aPos; m_pos = aPos;
m_shape.SetCenter( aPos ); m_shape.SetCenter( aPos );
if( m_hole ) if( m_hole )
m_hole->SetCenter( aPos ); m_hole->SetCenter( aPos );
} }
@ -136,6 +135,7 @@ public:
void SetDrill( int aDrill ) void SetDrill( int aDrill )
{ {
m_drill = aDrill; m_drill = aDrill;
if( m_hole ) if( m_hole )
m_hole->SetRadius( m_drill / 2 ); m_hole->SetRadius( m_drill / 2 );
} }
@ -171,19 +171,14 @@ public:
virtual void SetHole( HOLE* aHole ) override virtual void SetHole( HOLE* aHole ) override
{ {
if( m_hole && m_hole->Owner() == this ) if( m_hole && m_hole->BelongsTo( this ) )
{
delete m_hole; delete m_hole;
}
m_hole = aHole; m_hole = aHole;
m_hole->SetParentPadVia( this ); m_hole->SetParentPadVia( this );
m_hole->SetOwner( this ); m_hole->SetOwner( this );
m_hole->SetLayers( m_layers ); // fixme: backdrill vias can have hole layer set different
if( m_hole ) // than copper layer set
{
m_hole->SetLayers( m_layers ); // fixme: backdrill vias can have hole layer set different than copper layer set
}
} }
virtual bool HasHole() const override { return true; } virtual bool HasHole() const override { return true; }