From 81a7af5704fcc453a2c61393f6d4d872449cf994 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 9 Jan 2012 15:26:55 -0500 Subject: [PATCH] Eeschema schematic object improvements. * Remove unnecessary copy constructors from schematic and component library objects. * Add comment to class definitions where the default copy constructor generated by the compiler was adequate. * Add assignment operator to EDA_ITEM, SCH_ITEM, and all schematic objects where the default assignment operator generated by the compiler would not be adequate. --- common/base_struct.cpp | 21 +++++++++++++++++++++ common/sch_item_struct.cpp | 17 +++++++++++++++++ eeschema/edit_bitmap.cpp | 13 ++++++++----- eeschema/lib_arc.cpp | 13 ------------- eeschema/lib_arc.h | 4 +++- eeschema/lib_bezier.cpp | 9 --------- eeschema/lib_bezier.h | 4 +++- eeschema/lib_circle.cpp | 10 ---------- eeschema/lib_circle.h | 4 +++- eeschema/lib_draw_item.cpp | 14 ++------------ eeschema/lib_draw_item.h | 2 +- eeschema/lib_field.cpp | 17 ----------------- eeschema/lib_field.h | 5 ++++- eeschema/lib_pin.cpp | 16 ---------------- eeschema/lib_pin.h | 4 +++- eeschema/lib_polyline.cpp | 8 -------- eeschema/lib_polyline.h | 4 +++- eeschema/lib_rectangle.cpp | 10 ---------- eeschema/lib_rectangle.h | 5 +++-- eeschema/lib_text.cpp | 2 +- eeschema/lib_text.h | 4 +++- eeschema/sch_bitmap.cpp | 21 +++++++++++++++++++++ eeschema/sch_bitmap.h | 1 + eeschema/sch_bus_entry.cpp | 9 --------- eeschema/sch_bus_entry.h | 2 +- eeschema/sch_component.cpp | 31 +++++++++++++++++++++++++++++++ eeschema/sch_component.h | 2 ++ eeschema/sch_field.cpp | 9 --------- eeschema/sch_field.h | 4 ++-- eeschema/sch_junction.cpp | 8 -------- eeschema/sch_junction.h | 2 +- eeschema/sch_line.h | 2 ++ eeschema/sch_marker.cpp | 7 ------- eeschema/sch_marker.h | 5 ++++- eeschema/sch_no_connect.cpp | 8 -------- eeschema/sch_no_connect.h | 2 +- eeschema/sch_polyline.cpp | 8 -------- eeschema/sch_polyline.h | 2 +- eeschema/sch_sheet.cpp | 33 +++++++++++++++++++++++++++++++++ eeschema/sch_sheet.h | 9 ++++++++- eeschema/sch_sheet_pin.cpp | 8 -------- eeschema/sch_text.cpp | 18 ------------------ eeschema/sch_text.h | 13 ++++++++++--- include/base_struct.h | 9 +++++++++ include/sch_item_struct.h | 4 +++- 45 files changed, 205 insertions(+), 198 deletions(-) diff --git a/common/base_struct.cpp b/common/base_struct.cpp index 5d1655e39a..869a077bc4 100644 --- a/common/base_struct.cpp +++ b/common/base_struct.cpp @@ -212,6 +212,27 @@ bool EDA_ITEM::operator<( const EDA_ITEM& aItem ) const } +EDA_ITEM& EDA_ITEM::operator=( const EDA_ITEM& aItem ) +{ + wxCHECK_MSG( Type() == aItem.Type(), *this, + wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) + + GetClass() ); + + if( &aItem != this ) + { + // Do not assign the linked list pointers. + m_StructType = aItem.m_StructType; + m_Parent = aItem.m_Parent; + m_Son = aItem.m_Son; + m_Flags = aItem.m_Flags; + SetTimeStamp( aItem.m_TimeStamp ); + m_Status = aItem.m_Status; + } + + return *this; +} + + #if defined(DEBUG) // A function that should have been in wxWidgets diff --git a/common/sch_item_struct.cpp b/common/sch_item_struct.cpp index 90f88bf652..7bffdcb634 100644 --- a/common/sch_item_struct.cpp +++ b/common/sch_item_struct.cpp @@ -102,6 +102,23 @@ bool SCH_ITEM::operator < ( const SCH_ITEM& aItem ) const } +SCH_ITEM& SCH_ITEM::operator=( const SCH_ITEM& aItem ) +{ + wxCHECK_MSG( Type() == aItem.Type(), *this, + wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) + + GetClass() ); + + if( &aItem != this ) + { + EDA_ITEM::operator=( aItem ); + m_Layer = aItem.m_Layer; + m_connections = aItem.m_connections; + } + + return *this; +} + + void SCH_ITEM::doPlot( PLOTTER* aPlotter ) { wxFAIL_MSG( wxT( "doPlot() method not implemented for class " ) + GetClass() ); diff --git a/eeschema/edit_bitmap.cpp b/eeschema/edit_bitmap.cpp index f626f3bad4..43b040477f 100644 --- a/eeschema/edit_bitmap.cpp +++ b/eeschema/edit_bitmap.cpp @@ -1,7 +1,3 @@ -/** - * @file edit_bitmap.cpp - */ - /* * This program source code file is part of KiCad, a free EDA CAD application. * @@ -26,6 +22,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +/** + * @file edit_bitmap.cpp + */ + #include "fctsys.h" #include "gr_basic.h" #include "macros.h" @@ -39,6 +39,9 @@ #include "sch_bitmap.h" #include "dialog_image_editor.h" +#include + + static void abortMoveBitmap( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) { SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen(); @@ -67,7 +70,7 @@ static void abortMoveBitmap( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) // Never delete existing item, because it can be referenced by an undo/redo command // Just restore its data - item->SwapData( olditem ); + swap( *item, *olditem ); } screen->SetCurItem( item ); diff --git a/eeschema/lib_arc.cpp b/eeschema/lib_arc.cpp index 5c0c16b055..44f1170e03 100644 --- a/eeschema/lib_arc.cpp +++ b/eeschema/lib_arc.cpp @@ -92,19 +92,6 @@ LIB_ARC::LIB_ARC( LIB_COMPONENT* aParent ) : LIB_ITEM( LIB_ARC_T, aParent ) } -LIB_ARC::LIB_ARC( const LIB_ARC& aArc ) : LIB_ITEM( aArc ) -{ - m_Radius = aArc.m_Radius; - m_t1 = aArc.m_t1; - m_t2 = aArc.m_t2; - m_Width = aArc.m_Width; - m_Fill = aArc.m_Fill; - m_Pos = aArc.m_Pos; - m_ArcStart = aArc.m_ArcStart; - m_ArcEnd = aArc.m_ArcEnd; -} - - bool LIB_ARC::Save( OUTPUTFORMATTER& aFormatter ) { int x1 = m_t1; diff --git a/eeschema/lib_arc.h b/eeschema/lib_arc.h index 008972de29..c6b268bf9e 100644 --- a/eeschema/lib_arc.h +++ b/eeschema/lib_arc.h @@ -85,7 +85,9 @@ class LIB_ARC : public LIB_ITEM public: LIB_ARC( LIB_COMPONENT * aParent ); - LIB_ARC( const LIB_ARC& aArc ); + + // Do not create a copy constructor. The one generated by the compiler is adequate. + ~LIB_ARC() { } virtual wxString GetClass() const diff --git a/eeschema/lib_bezier.cpp b/eeschema/lib_bezier.cpp index 330aa0bc93..d0a24b77dd 100644 --- a/eeschema/lib_bezier.cpp +++ b/eeschema/lib_bezier.cpp @@ -53,15 +53,6 @@ LIB_BEZIER::LIB_BEZIER( LIB_COMPONENT* aParent ) : } -LIB_BEZIER::LIB_BEZIER( const LIB_BEZIER& aBezier ) : LIB_ITEM( aBezier ) -{ - m_PolyPoints = aBezier.m_PolyPoints; - m_BezierPoints = aBezier.m_BezierPoints; // Vector copy - m_Width = aBezier.m_Width; - m_Fill = aBezier.m_Fill; -} - - bool LIB_BEZIER::Save( OUTPUTFORMATTER& aFormatter ) { int ccount = GetCornerCount(); diff --git a/eeschema/lib_bezier.h b/eeschema/lib_bezier.h index b1c193468d..066deea579 100644 --- a/eeschema/lib_bezier.h +++ b/eeschema/lib_bezier.h @@ -51,7 +51,9 @@ class LIB_BEZIER : public LIB_ITEM public: LIB_BEZIER( LIB_COMPONENT * aParent ); - LIB_BEZIER( const LIB_BEZIER& aBezier ); + + // Do not create a copy constructor. The one generated by the compiler is adequate. + ~LIB_BEZIER() { } virtual wxString GetClass() const diff --git a/eeschema/lib_circle.cpp b/eeschema/lib_circle.cpp index 391583655b..7bf748f521 100644 --- a/eeschema/lib_circle.cpp +++ b/eeschema/lib_circle.cpp @@ -54,16 +54,6 @@ LIB_CIRCLE::LIB_CIRCLE( LIB_COMPONENT* aParent ) : } -LIB_CIRCLE::LIB_CIRCLE( const LIB_CIRCLE& aCircle ) : - LIB_ITEM( aCircle ) -{ - m_Pos = aCircle.m_Pos; - m_Radius = aCircle.m_Radius; - m_Fill = aCircle.m_Fill; - m_Width = aCircle.m_Width; -} - - bool LIB_CIRCLE::Save( OUTPUTFORMATTER& aFormatter ) { aFormatter.Print( 0, "C %d %d %d %d %d %d %c\n", m_Pos.x, m_Pos.y, diff --git a/eeschema/lib_circle.h b/eeschema/lib_circle.h index 9eab5759a9..e17c6ac0bf 100644 --- a/eeschema/lib_circle.h +++ b/eeschema/lib_circle.h @@ -54,7 +54,9 @@ class LIB_CIRCLE : public LIB_ITEM public: LIB_CIRCLE( LIB_COMPONENT * aParent ); - LIB_CIRCLE( const LIB_CIRCLE& aCircle ); + + // Do not create a copy constructor. The one generated by the compiler is adequate. + ~LIB_CIRCLE() { } virtual wxString GetClass() const diff --git a/eeschema/lib_draw_item.cpp b/eeschema/lib_draw_item.cpp index 32293af452..b4d54c904b 100644 --- a/eeschema/lib_draw_item.cpp +++ b/eeschema/lib_draw_item.cpp @@ -58,18 +58,6 @@ LIB_ITEM::LIB_ITEM( KICAD_T aType, } -LIB_ITEM::LIB_ITEM( const LIB_ITEM& aItem ) : - EDA_ITEM( aItem ) -{ - m_Unit = aItem.m_Unit; - m_Convert = aItem.m_Convert; - m_Fill = aItem.m_Fill; - m_typeName = aItem.m_typeName; - m_isFillable = aItem.m_isFillable; - m_eraseLastDrawItem = false; -} - - void LIB_ITEM::DisplayInfo( EDA_DRAW_FRAME* aFrame ) { wxString msg; @@ -81,6 +69,7 @@ void LIB_ITEM::DisplayInfo( EDA_DRAW_FRAME* aFrame ) msg = _( "All" ); else msg.Printf( wxT( "%d" ), m_Unit ); + aFrame->AppendMsgPanel( _( "Unit" ), msg, BROWN ); if( m_Convert == 0 ) @@ -91,6 +80,7 @@ void LIB_ITEM::DisplayInfo( EDA_DRAW_FRAME* aFrame ) msg = _( "yes" ); else msg = wxT( "?" ); + aFrame->AppendMsgPanel( _( "Convert" ), msg, BROWN ); } diff --git a/eeschema/lib_draw_item.h b/eeschema/lib_draw_item.h index 7e6dbd0de3..28983a3775 100644 --- a/eeschema/lib_draw_item.h +++ b/eeschema/lib_draw_item.h @@ -143,7 +143,7 @@ public: int aConvert = 0, FILL_T aFillType = NO_FILL ); - LIB_ITEM( const LIB_ITEM& aItem ); + // Do not create a copy constructor. The one generated by the compiler is adequate. virtual ~LIB_ITEM() { } diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index b5cad9f212..d9b64e53a3 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -59,23 +59,6 @@ LIB_FIELD::LIB_FIELD( int idfield ) : LIB_ITEM( LIB_FIELD_T, NULL ) } -LIB_FIELD::LIB_FIELD( const LIB_FIELD& field ) : LIB_ITEM( field ) -{ - m_id = field.m_id; - m_Pos = field.m_Pos; - m_Size = field.m_Size; - m_Thickness = field.m_Thickness; - m_Orient = field.m_Orient; - m_Attributs = field.m_Attributs; - m_Text = field.m_Text; - m_name = field.m_name; - m_HJustify = field.m_HJustify; - m_VJustify = field.m_VJustify; - m_Italic = field.m_Italic; - m_Bold = field.m_Bold; -} - - LIB_FIELD::~LIB_FIELD() { } diff --git a/eeschema/lib_field.h b/eeschema/lib_field.h index 68cfa4297a..105346577e 100644 --- a/eeschema/lib_field.h +++ b/eeschema/lib_field.h @@ -83,8 +83,11 @@ class LIB_FIELD : public LIB_ITEM, public EDA_TEXT public: LIB_FIELD( int idfield = 2 ); + LIB_FIELD( LIB_COMPONENT * aParent, int idfield = 2 ); - LIB_FIELD( const LIB_FIELD& field ); + + // Do not create a copy constructor. The one generated by the compiler is adequate. + ~LIB_FIELD(); virtual wxString GetClass() const diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp index ffc9c7aadb..c56a73255f 100644 --- a/eeschema/lib_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -198,22 +198,6 @@ LIB_PIN::LIB_PIN( LIB_COMPONENT* aParent ) : } -LIB_PIN::LIB_PIN( const LIB_PIN& pin ) : LIB_ITEM( pin ) -{ - m_position = pin.m_position; - m_length = pin.m_length; - m_orientation = pin.m_orientation; - m_shape = pin.m_shape; - m_type = pin.m_type; - m_attributes = pin.m_attributes; - m_number = pin.m_number; - m_numTextSize = pin.m_numTextSize; - m_nameTextSize = pin.m_nameTextSize; - m_width = pin.m_width; - m_name = pin.m_name; -} - - void LIB_PIN::SetName( const wxString& aName ) { wxString tmp = ( aName.IsEmpty() ) ? wxT( "~" ) : aName; diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h index d99fbd93ad..33f2f0e15d 100644 --- a/eeschema/lib_pin.h +++ b/eeschema/lib_pin.h @@ -125,7 +125,9 @@ class LIB_PIN : public LIB_ITEM public: LIB_PIN( LIB_COMPONENT* aParent ); - LIB_PIN( const LIB_PIN& aPin ); + + // Do not create a copy constructor. The one generated by the compiler is adequate. + ~LIB_PIN() { } virtual wxString GetClass() const diff --git a/eeschema/lib_polyline.cpp b/eeschema/lib_polyline.cpp index 40fcd1b88f..b757f605bd 100644 --- a/eeschema/lib_polyline.cpp +++ b/eeschema/lib_polyline.cpp @@ -54,14 +54,6 @@ LIB_POLYLINE::LIB_POLYLINE( LIB_COMPONENT* aParent ) : } -LIB_POLYLINE::LIB_POLYLINE( const LIB_POLYLINE& polyline ) : - LIB_ITEM( polyline ) -{ - m_PolyPoints = polyline.m_PolyPoints; // Vector copy - m_Width = polyline.m_Width; -} - - bool LIB_POLYLINE::Save( OUTPUTFORMATTER& aFormatter ) { int ccount = GetCornerCount(); diff --git a/eeschema/lib_polyline.h b/eeschema/lib_polyline.h index 89d9caace7..cc96eba728 100644 --- a/eeschema/lib_polyline.h +++ b/eeschema/lib_polyline.h @@ -55,7 +55,9 @@ class LIB_POLYLINE : public LIB_ITEM public: LIB_POLYLINE( LIB_COMPONENT * aParent ); - LIB_POLYLINE( const LIB_POLYLINE& aPolyline ); + + // Do not create a copy constructor. The one generated by the compiler is adequate. + ~LIB_POLYLINE() { } virtual wxString GetClass() const diff --git a/eeschema/lib_rectangle.cpp b/eeschema/lib_rectangle.cpp index 438552324e..8413a9d34b 100644 --- a/eeschema/lib_rectangle.cpp +++ b/eeschema/lib_rectangle.cpp @@ -55,16 +55,6 @@ LIB_RECTANGLE::LIB_RECTANGLE( LIB_COMPONENT* aParent ) : } -LIB_RECTANGLE::LIB_RECTANGLE( const LIB_RECTANGLE& aRect ) : - LIB_ITEM( aRect ) -{ - m_Pos = aRect.m_Pos; - m_End = aRect.m_End; - m_Width = aRect.m_Width; - m_Fill = aRect.m_Fill; -} - - bool LIB_RECTANGLE::Save( OUTPUTFORMATTER& aFormatter ) { aFormatter.Print( 0, "S %d %d %d %d %d %d %d %c\n", m_Pos.x, m_Pos.y, diff --git a/eeschema/lib_rectangle.h b/eeschema/lib_rectangle.h index 4d9fa192a4..7ffe79fc4f 100644 --- a/eeschema/lib_rectangle.h +++ b/eeschema/lib_rectangle.h @@ -55,10 +55,11 @@ class LIB_RECTANGLE : public LIB_ITEM */ void calcEdit( const wxPoint& aPosition ); -public: public: LIB_RECTANGLE( LIB_COMPONENT * aParent ); - LIB_RECTANGLE( const LIB_RECTANGLE& aRect ); + + // Do not create a copy constructor. The one generated by the compiler is adequate. + ~LIB_RECTANGLE() { } virtual wxString GetClass() const diff --git a/eeschema/lib_text.cpp b/eeschema/lib_text.cpp index 391d472033..a05787b550 100644 --- a/eeschema/lib_text.cpp +++ b/eeschema/lib_text.cpp @@ -44,7 +44,7 @@ #include "lib_text.h" -LIB_TEXT::LIB_TEXT(LIB_COMPONENT * aParent) : +LIB_TEXT::LIB_TEXT( LIB_COMPONENT * aParent ) : LIB_ITEM( LIB_TEXT_T, aParent ), EDA_TEXT() { diff --git a/eeschema/lib_text.h b/eeschema/lib_text.h index 5dfe4a9aab..2cf32f4b79 100644 --- a/eeschema/lib_text.h +++ b/eeschema/lib_text.h @@ -62,7 +62,9 @@ class LIB_TEXT : public LIB_ITEM, public EDA_TEXT public: LIB_TEXT( LIB_COMPONENT * aParent ); - LIB_TEXT( const LIB_TEXT& aText ); + + // Do not create a copy constructor. The one generated by the compiler is adequate. + ~LIB_TEXT() { } virtual wxString GetClass() const diff --git a/eeschema/sch_bitmap.cpp b/eeschema/sch_bitmap.cpp index 2007bde7f7..8812733b64 100644 --- a/eeschema/sch_bitmap.cpp +++ b/eeschema/sch_bitmap.cpp @@ -67,6 +67,27 @@ SCH_BITMAP::SCH_BITMAP( const SCH_BITMAP& aSchBitmap ) : } +SCH_ITEM& SCH_BITMAP::operator=( const SCH_ITEM& aItem ) +{ + wxCHECK_MSG( Type() == aItem.Type(), *this, + wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) + + GetClass() ); + + if( &aItem != this ) + { + SCH_ITEM::operator=( aItem ); + + SCH_BITMAP* bitmap = (SCH_BITMAP*) &aItem; + + delete m_Image; + m_Image = new BITMAP_BASE( *bitmap->m_Image ); + m_Pos = bitmap->m_Pos; + } + + return *this; +} + + bool SCH_BITMAP::ReadImageFile( const wxString& aFullFilename ) { return m_Image->ReadImageFile( aFullFilename ); diff --git a/eeschema/sch_bitmap.h b/eeschema/sch_bitmap.h index f6223a79e8..0114e0d693 100644 --- a/eeschema/sch_bitmap.h +++ b/eeschema/sch_bitmap.h @@ -53,6 +53,7 @@ public: delete m_Image; } + SCH_ITEM& operator=( const SCH_ITEM& aItem ); /* * Accessors: diff --git a/eeschema/sch_bus_entry.cpp b/eeschema/sch_bus_entry.cpp index 63db57e180..89c81b6698 100644 --- a/eeschema/sch_bus_entry.cpp +++ b/eeschema/sch_bus_entry.cpp @@ -61,15 +61,6 @@ SCH_BUS_ENTRY::SCH_BUS_ENTRY( const wxPoint& pos, int shape, int id ) : } -SCH_BUS_ENTRY::SCH_BUS_ENTRY( const SCH_BUS_ENTRY& aBusEntry ) : - SCH_ITEM( aBusEntry ) -{ - m_pos = aBusEntry.m_pos; - m_size = aBusEntry.m_size; - m_width = aBusEntry.m_width; -} - - EDA_ITEM* SCH_BUS_ENTRY::doClone() const { return new SCH_BUS_ENTRY( *this ); diff --git a/eeschema/sch_bus_entry.h b/eeschema/sch_bus_entry.h index 7b27a5801a..fcade2f9b0 100644 --- a/eeschema/sch_bus_entry.h +++ b/eeschema/sch_bus_entry.h @@ -53,7 +53,7 @@ class SCH_BUS_ENTRY : public SCH_ITEM public: SCH_BUS_ENTRY( const wxPoint& pos = wxPoint( 0, 0 ), int shape = '\\', int id = WIRE_TO_BUS ); - SCH_BUS_ENTRY( const SCH_BUS_ENTRY& aBusEntry ); + // Do not create a copy constructor. The one generated by the compiler is adequate. ~SCH_BUS_ENTRY() { } diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index 4bfd9547fa..93d9a2abf3 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -1780,6 +1780,37 @@ bool SCH_COMPONENT::operator <( const SCH_ITEM& aItem ) const } +SCH_ITEM& SCH_COMPONENT::operator=( const SCH_ITEM& aItem ) +{ + wxCHECK_MSG( Type() == aItem.Type(), *this, + wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) + + GetClass() ); + + if( &aItem != this ) + { + SCH_ITEM::operator=( aItem ); + + SCH_COMPONENT* component = (SCH_COMPONENT*) &aItem; + m_ChipName = component->m_ChipName; + m_Pos = component->m_Pos; + m_unit = component->m_unit; + m_convert = component->m_convert; + m_transform = component->m_transform; + m_PathsAndReferences = component->m_PathsAndReferences; + + m_Fields = component->m_Fields; // std::vector's assignment operator. + + // Reparent fields after assignment to new component. + for( int ii = 0; ii < GetFieldCount(); ++ii ) + { + GetField( ii )->SetParent( this ); + } + } + + return *this; +} + + bool SCH_COMPONENT::doHitTest( const wxPoint& aPoint, int aAccuracy ) const { EDA_RECT bBox = GetBodyBoundingBox(); diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h index e9abf6226d..1b36f4e398 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -401,6 +401,8 @@ public: virtual bool operator <( const SCH_ITEM& aItem ) const; + SCH_ITEM& operator=( const SCH_ITEM& aItem ); + /** * @copydoc EDA_ITEM::IsReplaceable() */ diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index b90684ede1..5be6be1bd0 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -80,15 +80,6 @@ SCH_FIELD::SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_COMPONENT* aParent, } -SCH_FIELD::SCH_FIELD( const SCH_FIELD& aField ) : - SCH_ITEM( aField ), - EDA_TEXT( aField ) -{ - m_id = aField.m_id; - m_name = aField.m_name; -} - - SCH_FIELD::~SCH_FIELD() { } diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 098dcfbbe8..198987558f 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -50,7 +50,7 @@ class LIB_FIELD; *
  • Field 1 is reserved for the component value.
  • *
  • Field 2 is reserved for the component footprint.
  • *
  • Field 3 is reserved for the component data sheet file.
  • - *
  • Fields 4 and higher are user defineable.
  • + *
  • Field 4 and higher are user defineable.
  • */ class SCH_FIELD : public SCH_ITEM, public EDA_TEXT @@ -63,7 +63,7 @@ public: SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_COMPONENT* aParent, wxString aName = wxEmptyString ); - SCH_FIELD( const SCH_FIELD& aField ); + // Do not create a copy constructor. The one generated by the compiler is adequate. ~SCH_FIELD(); diff --git a/eeschema/sch_junction.cpp b/eeschema/sch_junction.cpp index 8c2f1f0fa6..9c1c047752 100644 --- a/eeschema/sch_junction.cpp +++ b/eeschema/sch_junction.cpp @@ -53,14 +53,6 @@ SCH_JUNCTION::SCH_JUNCTION( const wxPoint& pos ) : } -SCH_JUNCTION::SCH_JUNCTION( const SCH_JUNCTION& aJunction ) : - SCH_ITEM( aJunction ) -{ - m_pos = aJunction.m_pos; - m_size = aJunction.m_size; -} - - bool SCH_JUNCTION::Save( FILE* aFile ) const { bool success = true; diff --git a/eeschema/sch_junction.h b/eeschema/sch_junction.h index f9ecc6f2fe..1b4d5a1db8 100644 --- a/eeschema/sch_junction.h +++ b/eeschema/sch_junction.h @@ -42,7 +42,7 @@ class SCH_JUNCTION : public SCH_ITEM public: SCH_JUNCTION( const wxPoint& pos = wxPoint( 0, 0 ) ); - SCH_JUNCTION( const SCH_JUNCTION& aJunction ); + // Do not create a copy constructor. The one generated by the compiler is adequate. ~SCH_JUNCTION() { } diff --git a/eeschema/sch_line.h b/eeschema/sch_line.h index bb1a748173..e1b0a444fe 100644 --- a/eeschema/sch_line.h +++ b/eeschema/sch_line.h @@ -49,7 +49,9 @@ class SCH_LINE : public SCH_ITEM public: SCH_LINE( const wxPoint& pos = wxPoint( 0, 0 ), int layer = LAYER_NOTES ); + SCH_LINE( const SCH_LINE& aLine ); + ~SCH_LINE() { } SCH_LINE* Next() const { return (SCH_LINE*) Pnext; } diff --git a/eeschema/sch_marker.cpp b/eeschema/sch_marker.cpp index 64dd15a1ad..8f52a5ea7c 100644 --- a/eeschema/sch_marker.cpp +++ b/eeschema/sch_marker.cpp @@ -43,13 +43,6 @@ SCH_MARKER::SCH_MARKER( const wxPoint& pos, const wxString& text ) : } -SCH_MARKER::SCH_MARKER( const SCH_MARKER& aMarker ) : - SCH_ITEM( aMarker ), - MARKER_BASE( aMarker ) -{ -} - - SCH_MARKER::~SCH_MARKER() { } diff --git a/eeschema/sch_marker.h b/eeschema/sch_marker.h index 82dae0c9c7..97f4f0ec10 100644 --- a/eeschema/sch_marker.h +++ b/eeschema/sch_marker.h @@ -55,8 +55,11 @@ class SCH_MARKER : public SCH_ITEM, public MARKER_BASE { public: SCH_MARKER(); + SCH_MARKER( const wxPoint& aPos, const wxString& aText ); - SCH_MARKER( const SCH_MARKER& aMarker ); + + // Do not create a copy constructor. The one generated by the compiler is adequate. + ~SCH_MARKER(); virtual wxString GetClass() const diff --git a/eeschema/sch_no_connect.cpp b/eeschema/sch_no_connect.cpp index 3b24b32c96..e49b296af4 100644 --- a/eeschema/sch_no_connect.cpp +++ b/eeschema/sch_no_connect.cpp @@ -55,14 +55,6 @@ SCH_NO_CONNECT::SCH_NO_CONNECT( const wxPoint& pos ) : } -SCH_NO_CONNECT::SCH_NO_CONNECT( const SCH_NO_CONNECT& aNoConnect ) : - SCH_ITEM( aNoConnect ) -{ - m_pos = aNoConnect.m_pos; - m_size = aNoConnect.m_size; -} - - EDA_ITEM* SCH_NO_CONNECT::doClone() const { return new SCH_NO_CONNECT( *this ); diff --git a/eeschema/sch_no_connect.h b/eeschema/sch_no_connect.h index ef32dc5eeb..f9b7ee2636 100644 --- a/eeschema/sch_no_connect.h +++ b/eeschema/sch_no_connect.h @@ -42,7 +42,7 @@ class SCH_NO_CONNECT : public SCH_ITEM public: SCH_NO_CONNECT( const wxPoint& pos = wxPoint( 0, 0 ) ); - SCH_NO_CONNECT( const SCH_NO_CONNECT& aNoConnect ); + // Do not create a copy constructor. The one generated by the compiler is adequate. ~SCH_NO_CONNECT() { } diff --git a/eeschema/sch_polyline.cpp b/eeschema/sch_polyline.cpp index 9d7e129690..82a48d4ec5 100644 --- a/eeschema/sch_polyline.cpp +++ b/eeschema/sch_polyline.cpp @@ -60,14 +60,6 @@ SCH_POLYLINE::SCH_POLYLINE( int layer ) : } -SCH_POLYLINE::SCH_POLYLINE( const SCH_POLYLINE& aPolyLine ) : - SCH_ITEM( aPolyLine ) -{ - m_width = aPolyLine.m_width; - m_points = aPolyLine.m_points; -} - - SCH_POLYLINE::~SCH_POLYLINE() { } diff --git a/eeschema/sch_polyline.h b/eeschema/sch_polyline.h index 082c88678b..e030775dba 100644 --- a/eeschema/sch_polyline.h +++ b/eeschema/sch_polyline.h @@ -43,7 +43,7 @@ class SCH_POLYLINE : public SCH_ITEM public: SCH_POLYLINE( int layer = LAYER_NOTES ); - SCH_POLYLINE( const SCH_POLYLINE& aPolyLine ); + // Do not create a copy constructor. The one generated by the compiler is adequate. ~SCH_POLYLINE(); diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 572668221c..66a3d171fc 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -1181,6 +1181,39 @@ void SCH_SHEET::doPlot( PLOTTER* aPlotter ) } +SCH_ITEM& SCH_SHEET::operator=( const SCH_ITEM& aItem ) +{ + wxLogDebug( wxT( "Sheet assignment operator." ) ); + + wxCHECK_MSG( Type() == aItem.Type(), *this, + wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) + + GetClass() ); + + if( &aItem != this ) + { + SCH_ITEM::operator=( aItem ); + + SCH_SHEET* sheet = (SCH_SHEET*) &aItem; + + m_pos = sheet->m_pos; + m_size = sheet->m_size; + m_name = sheet->m_name; + m_sheetNameSize = sheet->m_sheetNameSize; + m_fileNameSize = sheet->m_fileNameSize; + m_pins = sheet->m_pins; + + // Ensure sheet labels have their #m_Parent member pointing really on their + // parent, after assigning. + BOOST_FOREACH( SCH_SHEET_PIN& sheetPin, m_pins ) + { + sheetPin.SetParent( this ); + } + } + + return *this; +} + + #if defined(DEBUG) void SCH_SHEET::Show( int nestLevel, std::ostream& os ) const diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index 71aa97e4b9..f823c77818 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -88,7 +88,7 @@ public: const wxPoint& pos = wxPoint( 0, 0 ), const wxString& text = wxEmptyString ); - SCH_SHEET_PIN( const SCH_SHEET_PIN& aSheetLabel ); + // Do not create a copy constructor. The one generated by the compiler is adequate. ~SCH_SHEET_PIN() { } @@ -273,6 +273,11 @@ class SCH_SHEET : public SCH_ITEM public: SCH_SHEET( const wxPoint& pos = wxPoint( 0, 0 ) ); + /** + * Copy Constructor + * clones \a aSheet into a new object. All sheet pins are copied as is except and + * the SCH_SHEET_PIN's #m_Parent pointers are set to the new copied parent object. + */ SCH_SHEET( const SCH_SHEET& aSheet ); ~SCH_SHEET(); @@ -625,6 +630,8 @@ public: virtual void GetNetListItem( vector& aNetListItems, SCH_SHEET_PATH* aSheetPath ); + SCH_ITEM& operator=( const SCH_ITEM& aSheet ); + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const; // override #endif diff --git a/eeschema/sch_sheet_pin.cpp b/eeschema/sch_sheet_pin.cpp index 442dfd44a6..a1b4a89194 100644 --- a/eeschema/sch_sheet_pin.cpp +++ b/eeschema/sch_sheet_pin.cpp @@ -62,14 +62,6 @@ SCH_SHEET_PIN::SCH_SHEET_PIN( SCH_SHEET* parent, const wxPoint& pos, const wxStr } -SCH_SHEET_PIN::SCH_SHEET_PIN( const SCH_SHEET_PIN& aSheetLabel ) : - SCH_HIERLABEL( aSheetLabel ) -{ - m_number = aSheetLabel.m_number; - m_edge = aSheetLabel.m_edge; -} - - EDA_ITEM* SCH_SHEET_PIN::doClone() const { return new SCH_SHEET_PIN( *this ); diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 2f3efa46b2..60761e555e 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -759,12 +759,6 @@ SCH_LABEL::SCH_LABEL( const wxPoint& pos, const wxString& text ) : } -SCH_LABEL::SCH_LABEL( const SCH_LABEL& aLabel ) : - SCH_TEXT( aLabel ) -{ -} - - EDA_ITEM* SCH_LABEL::doClone() const { return new SCH_LABEL( *this ); @@ -967,12 +961,6 @@ SCH_GLOBALLABEL::SCH_GLOBALLABEL( const wxPoint& pos, const wxString& text ) : } -SCH_GLOBALLABEL::SCH_GLOBALLABEL( const SCH_GLOBALLABEL& aGlobalLabel ) : - SCH_TEXT( aGlobalLabel ) -{ -} - - EDA_ITEM* SCH_GLOBALLABEL::doClone() const { return new SCH_GLOBALLABEL( *this ); @@ -1402,12 +1390,6 @@ SCH_HIERLABEL::SCH_HIERLABEL( const wxPoint& pos, const wxString& text, KICAD_T } -SCH_HIERLABEL::SCH_HIERLABEL( const SCH_HIERLABEL& aHierLabel ) : - SCH_TEXT( aHierLabel ) -{ -} - - EDA_ITEM* SCH_HIERLABEL::doClone() const { return new SCH_HIERLABEL( *this ); diff --git a/eeschema/sch_text.h b/eeschema/sch_text.h index 6c2a19eedf..c7fac5b9fe 100644 --- a/eeschema/sch_text.h +++ b/eeschema/sch_text.h @@ -79,6 +79,13 @@ public: const wxString& text = wxEmptyString, KICAD_T aType = SCH_TEXT_T ); + /** + * Copy Constructor + * clones \a aText into a new object. All members are copied as is except + * for the #m_isDangling member which is set to false. This prevents newly + * copied objects derived from #SCH_TEXT from having their connection state + * improperly set. + */ SCH_TEXT( const SCH_TEXT& aText ); ~SCH_TEXT() { } @@ -257,7 +264,7 @@ class SCH_LABEL : public SCH_TEXT public: SCH_LABEL( const wxPoint& pos = wxPoint( 0, 0 ), const wxString& text = wxEmptyString ); - SCH_LABEL( const SCH_LABEL& aLabel ); + // Do not create a copy constructor. The one generated by the compiler is adequate. ~SCH_LABEL() { } @@ -352,7 +359,7 @@ class SCH_GLOBALLABEL : public SCH_TEXT public: SCH_GLOBALLABEL( const wxPoint& pos = wxPoint( 0, 0 ), const wxString& text = wxEmptyString ); - SCH_GLOBALLABEL( const SCH_GLOBALLABEL& aGlobalLabel ); + // Do not create a copy constructor. The one generated by the compiler is adequate. ~SCH_GLOBALLABEL() { } @@ -458,7 +465,7 @@ public: const wxString& text = wxEmptyString, KICAD_T aType = SCH_HIERARCHICAL_LABEL_T ); - SCH_HIERLABEL( const SCH_HIERLABEL& aHierLabel ); + // Do not create a copy constructor. The one generated by the compiler is adequate. ~SCH_HIERLABEL() { } diff --git a/include/base_struct.h b/include/base_struct.h index 2c441b541b..822cf4276c 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -698,6 +698,15 @@ public: */ static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; } + /** + * Operator assignment + * is used to assign the members of \a aItem to another object. + * + * @warning This is still a work in progress and not ready for prime time. Do not use + * as there is a known issue with wxString buffers. + */ + virtual EDA_ITEM& operator=( const EDA_ITEM& aItem ); + #if defined(DEBUG) /** diff --git a/include/sch_item_struct.h b/include/sch_item_struct.h index 42c1e3717e..a794824aea 100644 --- a/include/sch_item_struct.h +++ b/include/sch_item_struct.h @@ -141,7 +141,7 @@ public: SCH_ITEM* Clone() const { return ( SCH_ITEM* ) EDA_ITEM::Clone(); } /** - * Function SwapDate + * Function SwapData * swap the internal data structures \a aItem with the schematic item. * Obviously, aItem must have the same type than me * @param aItem The item to swap the data structures with. @@ -352,6 +352,8 @@ public: virtual bool operator <( const SCH_ITEM& aItem ) const; + virtual SCH_ITEM& operator=( const SCH_ITEM& aItem ); + /** * @note - The DoXXX() functions below are used to enforce the interface while retaining * the ability of change the implementation behavior of derived classes. See