pcbnew: Adding copy constructors to PNS items

Adding safe copy constructors to PNS items including assignment check
and copy operations
This commit is contained in:
Seth Hillbrand 2018-10-08 07:13:04 -07:00
parent e1fe3c7ed4
commit 41e4bc4d9f
8 changed files with 98 additions and 19 deletions

View File

@ -84,6 +84,18 @@ public:
SHAPE( SH_LINE_CHAIN ), m_points( aShape.m_points ), m_closed( aShape.m_closed ) SHAPE( SH_LINE_CHAIN ), m_points( aShape.m_points ), m_closed( aShape.m_closed )
{} {}
SHAPE_LINE_CHAIN& operator=( const SHAPE_LINE_CHAIN& aShape )
{
if( this == &aShape )
return *this;
m_type = SH_LINE_CHAIN;
m_points = aShape.m_points;
m_closed = aShape.m_closed;
return *this;
}
/** /**
* Constructor * Constructor
* Initializes a 2-point line chain (a single segment) * Initializes a 2-point line chain (a single segment)
@ -376,14 +388,8 @@ public:
*/ */
void Append( const VECTOR2I& aP, bool aAllowDuplication = false ) void Append( const VECTOR2I& aP, bool aAllowDuplication = false )
{ {
if( m_points.size() == 0 )
m_bbox = BOX2I( aP, VECTOR2I( 0, 0 ) );
if( m_points.size() == 0 || aAllowDuplication || CPoint( -1 ) != aP ) if( m_points.size() == 0 || aAllowDuplication || CPoint( -1 ) != aP )
{
m_points.push_back( aP ); m_points.push_back( aP );
m_bbox.Merge( aP );
}
} }
/** /**
@ -401,14 +407,12 @@ public:
{ {
const VECTOR2I p = aOtherLine.CPoint( 0 ); const VECTOR2I p = aOtherLine.CPoint( 0 );
m_points.push_back( p ); m_points.push_back( p );
m_bbox.Merge( p );
} }
for( int i = 1; i < aOtherLine.PointCount(); i++ ) for( int i = 1; i < aOtherLine.PointCount(); i++ )
{ {
const VECTOR2I p = aOtherLine.CPoint( i ); const VECTOR2I p = aOtherLine.CPoint( i );
m_points.push_back( p ); m_points.push_back( p );
m_bbox.Merge( p );
} }
} }
@ -673,9 +677,6 @@ private:
/// is the line chain closed? /// is the line chain closed?
bool m_closed; bool m_closed;
/// cached bounding box
BOX2I m_bbox;
}; };
#endif // __SHAPE_LINE_CHAIN #endif // __SHAPE_LINE_CHAIN

View File

@ -40,6 +40,18 @@ public:
SHAPE_SEGMENT( const SEG& aSeg, int aWidth = 0 ): SHAPE_SEGMENT( const SEG& aSeg, int aWidth = 0 ):
SHAPE( SH_SEGMENT ), m_seg( aSeg ), m_width( aWidth ) {}; SHAPE( SH_SEGMENT ), m_seg( aSeg ), m_width( aWidth ) {};
SHAPE_SEGMENT& operator=( const SHAPE_SEGMENT& aOther )
{
if( this == &aOther )
return *this;
SHAPE::operator=( aOther );
m_seg = aOther.m_seg;
m_width = aOther.m_width;
return *this;
}
~SHAPE_SEGMENT() {}; ~SHAPE_SEGMENT() {};
SHAPE* Clone() const override SHAPE* Clone() const override

View File

@ -92,6 +92,24 @@ public:
m_routable = aOther.m_routable; m_routable = aOther.m_routable;
} }
ITEM& operator=( const ITEM& aOther )
{
if( this == &aOther )
return *this;
m_layers = aOther.m_layers;
m_net = aOther.m_net;
m_movable = aOther.m_movable;
m_kind = aOther.m_kind;
m_parent = aOther.m_parent;
m_owner = NULL;
m_marker = aOther.m_marker;
m_rank = aOther.m_rank;
m_routable = aOther.m_routable;
return *this;
}
virtual ~ITEM(); virtual ~ITEM();
/** /**

View File

@ -82,14 +82,26 @@ public:
JOINT( const JOINT& aB ) : JOINT( const JOINT& aB ) :
ITEM( JOINT_T ) ITEM( JOINT_T )
{ {
m_layers = aB.m_layers;
m_tag.pos = aB.m_tag.pos; m_tag.pos = aB.m_tag.pos;
m_tag.net = aB.m_tag.net; m_tag.net = aB.m_tag.net;
m_linkedItems = aB.m_linkedItems; m_linkedItems = aB.m_linkedItems;
m_layers = aB.m_layers;
m_locked = aB.m_locked; m_locked = aB.m_locked;
} }
JOINT& operator=( const JOINT& aOther )
{
if( this == &aOther )
return *this;
ITEM::operator =( aOther );
m_tag.pos = aOther.m_tag.pos;
m_tag.net = aOther.m_tag.net;
m_linkedItems = aOther.m_linkedItems;
m_locked = aOther.m_locked;
return *this;
}
ITEM* Clone( ) const override ITEM* Clone( ) const override
{ {
assert( false ); assert( false );

View File

@ -57,16 +57,15 @@ LINE::~LINE()
LINE& LINE::operator=( const LINE& aOther ) LINE& LINE::operator=( const LINE& aOther )
{ {
if( this == &aOther )
return *this;
ITEM::operator =( aOther );
m_line = aOther.m_line; m_line = aOther.m_line;
m_width = aOther.m_width; m_width = aOther.m_width;
m_net = aOther.m_net;
m_movable = aOther.m_movable;
m_layers = aOther.m_layers;
m_via = aOther.m_via; m_via = aOther.m_via;
m_hasVia = aOther.m_hasVia; m_hasVia = aOther.m_hasVia;
m_marker = aOther.m_marker;
m_rank = aOther.m_rank;
copyLinks( &aOther ); copyLinks( &aOther );
return *this; return *this;

View File

@ -58,6 +58,16 @@ public:
m_rank = aParentLine.Rank(); m_rank = aParentLine.Rank();
} }
SEGMENT& operator=( const SEGMENT& aOther )
{
if( this == &aOther )
return *this;
ITEM::operator =( aOther );
m_seg = aOther.m_seg;
return *this;
}
static inline bool ClassOf( const ITEM* aItem ) static inline bool ClassOf( const ITEM* aItem )
{ {
return aItem && SEGMENT_T == aItem->Kind(); return aItem && SEGMENT_T == aItem->Kind();

View File

@ -52,6 +52,18 @@ public:
m_pos = aSolid.m_pos; m_pos = aSolid.m_pos;
} }
SOLID& operator=( const SOLID& aOther )
{
if( this == &aOther )
return *this;
ITEM::operator =( aOther );
m_shape = aOther.m_shape->Clone();
m_pos = aOther.m_pos;
return *this;
}
static inline bool ClassOf( const ITEM* aItem ) static inline bool ClassOf( const ITEM* aItem )
{ {
return aItem && SOLID_T == aItem->Kind(); return aItem && SOLID_T == aItem->Kind();

View File

@ -79,6 +79,21 @@ public:
m_viaType = aB.m_viaType; m_viaType = aB.m_viaType;
} }
VIA& operator=( const VIA& aOther )
{
if( this == &aOther )
return *this;
ITEM::operator =( aOther );
m_pos = aOther.m_pos;
m_diameter = aOther.m_diameter;
m_shape = SHAPE_CIRCLE( m_pos, m_diameter / 2 );
m_drill = aOther.m_drill;
m_viaType = aOther.m_viaType;
return *this;
}
static inline bool ClassOf( const ITEM* aItem ) static inline bool ClassOf( const ITEM* aItem )
{ {
return aItem && VIA_T == aItem->Kind(); return aItem && VIA_T == aItem->Kind();