From 41e4bc4d9fe52c81986ad1522dc3f8965a4ef6bf Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 8 Oct 2018 07:13:04 -0700 Subject: [PATCH] pcbnew: Adding copy constructors to PNS items Adding safe copy constructors to PNS items including assignment check and copy operations --- include/geometry/shape_line_chain.h | 23 ++++++++++++----------- include/geometry/shape_segment.h | 12 ++++++++++++ pcbnew/router/pns_item.h | 18 ++++++++++++++++++ pcbnew/router/pns_joint.h | 16 ++++++++++++++-- pcbnew/router/pns_line.cpp | 11 +++++------ pcbnew/router/pns_segment.h | 10 ++++++++++ pcbnew/router/pns_solid.h | 12 ++++++++++++ pcbnew/router/pns_via.h | 15 +++++++++++++++ 8 files changed, 98 insertions(+), 19 deletions(-) diff --git a/include/geometry/shape_line_chain.h b/include/geometry/shape_line_chain.h index 250e0e797b..98584a0dc4 100644 --- a/include/geometry/shape_line_chain.h +++ b/include/geometry/shape_line_chain.h @@ -84,6 +84,18 @@ public: 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 * Initializes a 2-point line chain (a single segment) @@ -376,14 +388,8 @@ public: */ 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 ) - { m_points.push_back( aP ); - m_bbox.Merge( aP ); - } } /** @@ -401,14 +407,12 @@ public: { const VECTOR2I p = aOtherLine.CPoint( 0 ); m_points.push_back( p ); - m_bbox.Merge( p ); } for( int i = 1; i < aOtherLine.PointCount(); i++ ) { const VECTOR2I p = aOtherLine.CPoint( i ); m_points.push_back( p ); - m_bbox.Merge( p ); } } @@ -673,9 +677,6 @@ private: /// is the line chain closed? bool m_closed; - - /// cached bounding box - BOX2I m_bbox; }; #endif // __SHAPE_LINE_CHAIN diff --git a/include/geometry/shape_segment.h b/include/geometry/shape_segment.h index 50fa87cdc8..c62d4d1fae 100644 --- a/include/geometry/shape_segment.h +++ b/include/geometry/shape_segment.h @@ -40,6 +40,18 @@ public: SHAPE_SEGMENT( const SEG& aSeg, int aWidth = 0 ): 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* Clone() const override diff --git a/pcbnew/router/pns_item.h b/pcbnew/router/pns_item.h index a2d4975a6e..f34353a1d4 100644 --- a/pcbnew/router/pns_item.h +++ b/pcbnew/router/pns_item.h @@ -92,6 +92,24 @@ public: 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(); /** diff --git a/pcbnew/router/pns_joint.h b/pcbnew/router/pns_joint.h index 2e68b43779..419d089caf 100644 --- a/pcbnew/router/pns_joint.h +++ b/pcbnew/router/pns_joint.h @@ -82,14 +82,26 @@ public: JOINT( const JOINT& aB ) : ITEM( JOINT_T ) { - m_layers = aB.m_layers; m_tag.pos = aB.m_tag.pos; m_tag.net = aB.m_tag.net; m_linkedItems = aB.m_linkedItems; - m_layers = aB.m_layers; 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 { assert( false ); diff --git a/pcbnew/router/pns_line.cpp b/pcbnew/router/pns_line.cpp index bd83594250..74ab1189a3 100644 --- a/pcbnew/router/pns_line.cpp +++ b/pcbnew/router/pns_line.cpp @@ -57,16 +57,15 @@ LINE::~LINE() LINE& LINE::operator=( const LINE& aOther ) { + if( this == &aOther ) + return *this; + + ITEM::operator =( aOther ); + m_line = aOther.m_line; 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_hasVia = aOther.m_hasVia; - m_marker = aOther.m_marker; - m_rank = aOther.m_rank; - copyLinks( &aOther ); return *this; diff --git a/pcbnew/router/pns_segment.h b/pcbnew/router/pns_segment.h index d07229c8f5..1d2424bff7 100644 --- a/pcbnew/router/pns_segment.h +++ b/pcbnew/router/pns_segment.h @@ -58,6 +58,16 @@ public: 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 ) { return aItem && SEGMENT_T == aItem->Kind(); diff --git a/pcbnew/router/pns_solid.h b/pcbnew/router/pns_solid.h index a4d4a7d848..fecb8ca1d4 100644 --- a/pcbnew/router/pns_solid.h +++ b/pcbnew/router/pns_solid.h @@ -52,6 +52,18 @@ public: 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 ) { return aItem && SOLID_T == aItem->Kind(); diff --git a/pcbnew/router/pns_via.h b/pcbnew/router/pns_via.h index 8bb002837a..9b9df762d2 100644 --- a/pcbnew/router/pns_via.h +++ b/pcbnew/router/pns_via.h @@ -79,6 +79,21 @@ public: 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 ) { return aItem && VIA_T == aItem->Kind();