From f95628c1329e86bb71fbe69729674e52d3853555 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 30 May 2016 10:36:07 +0200 Subject: [PATCH 01/61] Switched to default constructor and operator= for EDA_TEXT. --- common/eda_text.cpp | 17 ----------------- include/eda_text.h | 5 ++++- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/common/eda_text.cpp b/common/eda_text.cpp index adf5c78ea7..6500c6eec1 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -66,23 +66,6 @@ EDA_TEXT::EDA_TEXT( const wxString& text ) } -EDA_TEXT::EDA_TEXT( const EDA_TEXT& aText ) -{ - m_Pos = aText.m_Pos; - m_Size = aText.m_Size; - m_Orient = aText.m_Orient; - m_Attributs = aText.m_Attributs; - m_Mirror = aText.m_Mirror; - m_HJustify = aText.m_HJustify; - m_VJustify = aText.m_VJustify; - m_Thickness = aText.m_Thickness; - m_Italic = aText.m_Italic; - m_Bold = aText.m_Bold; - m_MultilineAllowed = aText.m_MultilineAllowed; - m_Text = aText.m_Text; -} - - EDA_TEXT::~EDA_TEXT() { } diff --git a/include/eda_text.h b/include/eda_text.h index f82609da5c..aa2b6d4c1a 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -97,7 +97,10 @@ protected: public: EDA_TEXT( const wxString& text = wxEmptyString ); - EDA_TEXT( const EDA_TEXT& aText ); + + // Do not create a copy constructor & operator=. + // The ones generated by the compiler are adequate. + virtual ~EDA_TEXT(); /** From ec4531948f6e8e2777a4fc27fc69f343b6886421 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 30 May 2016 10:44:05 +0200 Subject: [PATCH 02/61] Move all SetParent() calls to a single location in BOARD::Add(). --- pcbnew/class_board.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 6bd301ef66..562ae0e2dc 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -869,18 +869,15 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) switch( aBoardItem->Type() ) { case PCB_NETINFO_T: - aBoardItem->SetParent( this ); m_NetInfo.AppendNet( (NETINFO_ITEM*) aBoardItem ); // this one uses a vector case PCB_MARKER_T: - aBoardItem->SetParent( this ); m_markers.push_back( (MARKER_PCB*) aBoardItem ); break; // this one uses a vector case PCB_ZONE_AREA_T: - aBoardItem->SetParent( this ); m_ZoneDescriptorList.push_back( (ZONE_CONTAINER*) aBoardItem ); break; @@ -897,7 +894,6 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) m_Track.Insert( (TRACK*) aBoardItem, insertAid ); } - aBoardItem->SetParent( this ); break; case PCB_ZONE_T: @@ -906,7 +902,6 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) else m_Zone.PushFront( (SEGZONE*) aBoardItem ); - aBoardItem->SetParent( this ); break; case PCB_MODULE_T: @@ -915,8 +910,6 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) else m_Modules.PushFront( (MODULE*) aBoardItem ); - aBoardItem->SetParent( this ); - // Because the list of pads has changed, reset the status // This indicate the list of pad and nets must be recalculated before use m_Status_Pcb = 0; @@ -934,7 +927,6 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) else m_Drawings.PushFront( aBoardItem ); - aBoardItem->SetParent( this ); break; // other types may use linked list @@ -944,10 +936,12 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) msg.Printf( wxT( "BOARD::Add() needs work: BOARD_ITEM type (%d) not handled" ), aBoardItem->Type() ); wxFAIL_MSG( msg ); + return; } break; } + aBoardItem->SetParent( this ); m_ratsnest->Add( aBoardItem ); } From 2c08ff1d598be737cd6b74316f29bb2e7a174149 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 30 May 2016 10:44:48 +0200 Subject: [PATCH 03/61] Switched to default copy ctor and/or operator= for BOARD, BOARD_CONNECTED_ITEM, DRAWSEGMENT & EDGE_MODULE. --- pcbnew/class_board.h | 13 +++++++++++++ pcbnew/class_board_connected_item.cpp | 7 ------- pcbnew/class_board_connected_item.h | 3 ++- pcbnew/class_drawsegment.cpp | 28 --------------------------- pcbnew/class_drawsegment.h | 8 ++------ pcbnew/class_edge_mod.cpp | 24 ----------------------- pcbnew/class_edge_mod.h | 9 ++------- 7 files changed, 19 insertions(+), 73 deletions(-) diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index cc827e46ca..e2a98bd31b 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -212,6 +212,19 @@ private: */ void chainMarkedSegments( wxPoint aPosition, const LSET& aLayerSet, TRACKS* aList ); + // The default copy constructor & operator= are inadequate, + // either write one or do not use it at all + BOARD( const BOARD& aOther ) : + BOARD_ITEM( aOther ), m_NetInfo( this ) + { + assert( false ); + } + + BOARD& operator=( const BOARD& aOther ) + { + assert( false ); + } + public: static inline bool ClassOf( const EDA_ITEM* aItem ) { diff --git a/pcbnew/class_board_connected_item.cpp b/pcbnew/class_board_connected_item.cpp index 0843728163..e996648b1b 100644 --- a/pcbnew/class_board_connected_item.cpp +++ b/pcbnew/class_board_connected_item.cpp @@ -41,13 +41,6 @@ BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype } -BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( const BOARD_CONNECTED_ITEM& aItem ) : - BOARD_ITEM( aItem ), m_netinfo( aItem.m_netinfo ), m_Subnet( aItem.m_Subnet ), - m_ZoneSubnet( aItem.m_ZoneSubnet ) -{ -} - - bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert ) { // if aNetCode < 0 ( typically NETINFO_LIST::FORCE_ORPHANED ) diff --git a/pcbnew/class_board_connected_item.h b/pcbnew/class_board_connected_item.h index 2fa293d392..cd694577ef 100644 --- a/pcbnew/class_board_connected_item.h +++ b/pcbnew/class_board_connected_item.h @@ -56,7 +56,8 @@ public: BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ); - BOARD_CONNECTED_ITEM( const BOARD_CONNECTED_ITEM& aItem ); + // Do not create a copy constructor & operator=. + // The ones generated by the compiler are adequate. static inline bool ClassOf( const EDA_ITEM* aItem ) { diff --git a/pcbnew/class_drawsegment.cpp b/pcbnew/class_drawsegment.cpp index c9ceb6ffa1..8dc8b1865c 100644 --- a/pcbnew/class_drawsegment.cpp +++ b/pcbnew/class_drawsegment.cpp @@ -64,34 +64,6 @@ DRAWSEGMENT::~DRAWSEGMENT() } -const DRAWSEGMENT& DRAWSEGMENT::operator = ( const DRAWSEGMENT& rhs ) -{ - // skip the linked list stuff, and parent - - m_Type = rhs.m_Type; - m_Layer = rhs.m_Layer; - m_Width = rhs.m_Width; - m_Start = rhs.m_Start; - m_End = rhs.m_End; - m_Shape = rhs.m_Shape; - m_Angle = rhs.m_Angle; - m_TimeStamp = rhs.m_TimeStamp; - m_BezierC1 = rhs.m_BezierC1; - m_BezierC2 = rhs.m_BezierC1; - m_BezierPoints = rhs.m_BezierPoints; - - return *this; -} - - -void DRAWSEGMENT::Copy( DRAWSEGMENT* source ) -{ - if( source == NULL ) // who would do this? - return; - - *this = *source; // operator = () -} - void DRAWSEGMENT::Rotate( const wxPoint& aRotCentre, double aAngle ) { switch( m_Shape ) diff --git a/pcbnew/class_drawsegment.h b/pcbnew/class_drawsegment.h index 411a5a2306..db8f3c8b18 100644 --- a/pcbnew/class_drawsegment.h +++ b/pcbnew/class_drawsegment.h @@ -65,13 +65,11 @@ protected: public: DRAWSEGMENT( BOARD_ITEM* aParent = NULL, KICAD_T idtype = PCB_LINE_T ); - // Do not create a copy constructor. The one generated by the compiler is adequate. + // Do not create a copy constructor & operator=. + // The ones generated by the compiler are adequate. ~DRAWSEGMENT(); - /// skip the linked list stuff, and parent - const DRAWSEGMENT& operator = ( const DRAWSEGMENT& rhs ); - static inline bool ClassOf( const EDA_ITEM* aItem ) { return aItem && PCB_LINE_T == aItem->Type(); @@ -181,8 +179,6 @@ public: m_PolyPoints = aPoints; } - void Copy( DRAWSEGMENT* source ); - void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset ); diff --git a/pcbnew/class_edge_mod.cpp b/pcbnew/class_edge_mod.cpp index 04376bbbf8..e49f7d7d15 100644 --- a/pcbnew/class_edge_mod.cpp +++ b/pcbnew/class_edge_mod.cpp @@ -65,30 +65,6 @@ EDGE_MODULE::~EDGE_MODULE() } -const EDGE_MODULE& EDGE_MODULE::operator = ( const EDGE_MODULE& rhs ) -{ - if( &rhs == this ) - return *this; - - DRAWSEGMENT::operator=( rhs ); - - m_Start0 = rhs.m_Start0; - m_End0 = rhs.m_End0; - - m_PolyPoints = rhs.m_PolyPoints; // std::vector copy - return *this; -} - - -void EDGE_MODULE::Copy( EDGE_MODULE* source ) -{ - if( source == NULL ) - return; - - *this = *source; -} - - void EDGE_MODULE::SetLocalCoord() { MODULE* module = (MODULE*) m_Parent; diff --git a/pcbnew/class_edge_mod.h b/pcbnew/class_edge_mod.h index f7ffcaaeb1..c89e1c7452 100644 --- a/pcbnew/class_edge_mod.h +++ b/pcbnew/class_edge_mod.h @@ -46,21 +46,16 @@ class EDGE_MODULE : public DRAWSEGMENT public: EDGE_MODULE( MODULE* parent, STROKE_T aShape = S_SEGMENT ); - // Do not create a copy constructor. The one generated by the compiler is adequate. - // EDGE_MODULE( const EDGE_MODULE& ); + // Do not create a copy constructor & operator=. + // The ones generated by the compiler are adequate. ~EDGE_MODULE(); - /// skip the linked list stuff, and parent - const EDGE_MODULE& operator = ( const EDGE_MODULE& rhs ); - static inline bool ClassOf( const EDA_ITEM* aItem ) { return aItem && PCB_MODULE_EDGE_T == aItem->Type(); } - void Copy( EDGE_MODULE* source ); // copy structure - /** * Move an edge of the footprint. * This is a footprint shape modification. From 09e0311d4ef3bc466f2d12b7de1ae2ab2117c249 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 31 May 2016 10:27:52 +0200 Subject: [PATCH 04/61] Replaced Copy() method with operator=. Removed Copy() where default copy ctor was enough. --- common/base_struct.cpp | 32 ++-- include/base_struct.h | 8 +- include/class_board_item.h | 3 +- pcbnew/board_undo_redo.cpp | 84 ++------- pcbnew/class_dimension.cpp | 24 --- pcbnew/class_dimension.h | 5 +- pcbnew/class_mire.cpp | 10 -- pcbnew/class_mire.h | 5 +- pcbnew/class_module.cpp | 164 ++++++++---------- pcbnew/class_module.h | 4 +- pcbnew/class_pad.cpp | 35 ---- pcbnew/class_pad.h | 6 +- pcbnew/class_pcb_text.cpp | 21 --- pcbnew/class_pcb_text.h | 6 +- pcbnew/class_text_mod.cpp | 21 --- pcbnew/class_text_mod.h | 5 +- pcbnew/class_zone.cpp | 53 +++--- pcbnew/class_zone.h | 8 +- .../dialog_edit_module_for_BoardEditor.cpp | 14 +- .../dialog_edit_module_for_Modedit.cpp | 14 +- pcbnew/dialogs/dialog_pad_properties.cpp | 4 +- pcbnew/edit_pcb_text.cpp | 4 +- pcbnew/pad_edition_functions.cpp | 2 +- pcbnew/zones_by_polygon.cpp | 3 +- pcbnew/zones_functions_for_undo_redo.cpp | 2 +- 25 files changed, 167 insertions(+), 370 deletions(-) diff --git a/common/base_struct.cpp b/common/base_struct.cpp index ecb6c13d71..b3d1c134fc 100644 --- a/common/base_struct.cpp +++ b/common/base_struct.cpp @@ -65,13 +65,7 @@ EDA_ITEM::EDA_ITEM( KICAD_T idType ) EDA_ITEM::EDA_ITEM( const EDA_ITEM& base ) { initVars(); - m_StructType = base.m_StructType; - m_Parent = base.m_Parent; - m_Flags = base.m_Flags; - - // A copy of an item cannot have the same time stamp as the original item. - SetTimeStamp( GetNewTimeStamp() ); - m_Status = base.m_Status; + *this = base; } @@ -224,23 +218,23 @@ bool EDA_ITEM::operator<( const EDA_ITEM& aItem ) const return false; } -#ifdef USE_EDA_ITEM_OP_EQ // see base_struct.h for explanations EDA_ITEM& EDA_ITEM::operator=( const EDA_ITEM& aItem ) { - if( &aItem != this ) - { - m_Image = aItem.m_Image; - m_StructType = aItem.m_StructType; - m_Parent = aItem.m_Parent; - m_Flags = aItem.m_Flags; - m_TimeStamp = aItem.m_TimeStamp; - m_Status = aItem.m_Status; - m_forceVisible = aItem.m_forceVisible; - } + // do not call initVars() + + m_StructType = aItem.m_StructType; + m_Flags = aItem.m_Flags; + m_Status = aItem.m_Status; + m_Parent = aItem.m_Parent; + m_forceVisible = aItem.m_forceVisible; + + // A copy of an item cannot have the same time stamp as the original item. + SetTimeStamp( GetNewTimeStamp() ); + + // do not copy list related fields (Pnext, Pback, m_List) return *this; } -#endif const BOX2I EDA_ITEM::ViewBBox() const { diff --git a/include/base_struct.h b/include/base_struct.h index 3d11391de9..88fcf98c49 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -482,17 +482,11 @@ public: */ static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; } -#if 0 /** * 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 ); - #define USE_EDA_ITEM_OP_EQ -#endif + EDA_ITEM& operator=( const EDA_ITEM& aItem ); /// @copydoc VIEW_ITEM::ViewBBox() virtual const BOX2I ViewBBox() const; diff --git a/include/class_board_item.h b/include/class_board_item.h index 6d9a2f928a..77a26a7a16 100644 --- a/include/class_board_item.h +++ b/include/class_board_item.h @@ -88,7 +88,8 @@ public: { } - // Do not create a copy constructor. The one generated by the compiler is adequate. + // Do not create a copy constructor & operator=. + // The ones generated by the compiler are adequate. virtual const wxPoint& GetPosition() const = 0; diff --git a/pcbnew/board_undo_redo.cpp b/pcbnew/board_undo_redo.cpp index c7aecac947..c8d52f7dc5 100644 --- a/pcbnew/board_undo_redo.cpp +++ b/pcbnew/board_undo_redo.cpp @@ -207,91 +207,35 @@ void BOARD_ITEM::SwapData( BOARD_ITEM* aImage ) switch( Type() ) { case PCB_MODULE_T: - { - MODULE* tmp = (MODULE*) aImage->Clone(); - ( (MODULE*) aImage )->Copy( (MODULE*) this ); - ( (MODULE*) this )->Copy( tmp ); - delete tmp; - } + std::swap( *((MODULE*) this), *((MODULE*) aImage) ); break; case PCB_ZONE_AREA_T: - { - ZONE_CONTAINER* tmp = (ZONE_CONTAINER*) aImage->Clone(); - ( (ZONE_CONTAINER*) aImage )->Copy( (ZONE_CONTAINER*) this ); - ( (ZONE_CONTAINER*) this )->Copy( tmp ); - delete tmp; - } + std::swap( *((ZONE_CONTAINER*) this), *((ZONE_CONTAINER*) aImage) ); break; case PCB_LINE_T: - std::swap( *((DRAWSEGMENT*)this), *((DRAWSEGMENT*)aImage) ); + std::swap( *((DRAWSEGMENT*) this), *((DRAWSEGMENT*) aImage) ); break; case PCB_TRACE_T: + std::swap( *((TRACK*) this), *((TRACK*) aImage) ); + break; + case PCB_VIA_T: - { - TRACK* track = (TRACK*) this; - TRACK* image = (TRACK*) aImage; - - std::swap(track->m_Layer, image->m_Layer ); - - // swap start, end, width and shape for track and image. - wxPoint exchp = track->GetStart(); - track->SetStart( image->GetStart() ); - image->SetStart( exchp ); - exchp = track->GetEnd(); - track->SetEnd( image->GetEnd() ); - image->SetEnd( exchp ); - - int atmp = track->GetWidth(); - track->SetWidth( image->GetWidth() ); - image->SetWidth( atmp ); - - if( Type() == PCB_VIA_T ) - { - VIA *via = static_cast( this ); - VIA *viaimage = static_cast( aImage ); - - VIATYPE_T viatmp = via->GetViaType(); - via->SetViaType( viaimage->GetViaType() ); - viaimage->SetViaType( viatmp ); - - int drilltmp = via->GetDrillValue(); - - if( via->IsDrillDefault() ) - drilltmp = -1; - - int itmp = viaimage->GetDrillValue(); - - if( viaimage->IsDrillDefault() ) - itmp = -1; - - std::swap(itmp, drilltmp ); - - if( drilltmp > 0 ) - via->SetDrill( drilltmp ); - else - via->SetDrillDefault(); - - if( itmp > 0 ) - viaimage->SetDrill( itmp ); - else - viaimage->SetDrillDefault(); - } - } + std::swap( *((VIA*) this), *((VIA*) aImage) ); break; case PCB_TEXT_T: - std::swap( *((TEXTE_PCB*)this), *((TEXTE_PCB*)aImage) ); + std::swap( *((TEXTE_PCB*) this), *((TEXTE_PCB*) aImage) ); break; case PCB_TARGET_T: - std::swap( *((PCB_TARGET*)this), *((PCB_TARGET*)aImage) ); + std::swap( *((PCB_TARGET*) this), *((PCB_TARGET*) aImage) ); break; case PCB_DIMENSION_T: - std::swap( *((DIMENSION*)this), *((DIMENSION*)aImage) ); + std::swap( *((DIMENSION*) this), *((DIMENSION*) aImage) ); break; case PCB_ZONE_T: @@ -417,7 +361,7 @@ void PCB_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, } if( !found ) - commandToUndo->PushItem( ITEM_PICKER(item, UR_CHANGED ) ); + commandToUndo->PushItem( ITEM_PICKER( item, UR_CHANGED ) ); else continue; @@ -572,6 +516,7 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed MODULE* oldModule = static_cast( item ); oldModule->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) ); } + view->Remove( item ); ratsnest->Remove( item ); @@ -583,11 +528,12 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed { MODULE* newModule = static_cast( item ); newModule->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1 ) ); + newModule->RunOnChildren( std::bind( &BOARD_ITEM::ClearFlags, _1, EDA_ITEM_ALL_FLAGS )); } + view->Add( item ); ratsnest->Add( item ); - - item->ClearFlags( SELECTED ); + item->ClearFlags(); item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS ); } break; diff --git a/pcbnew/class_dimension.cpp b/pcbnew/class_dimension.cpp index fab0cd2142..bcdb38abf5 100644 --- a/pcbnew/class_dimension.cpp +++ b/pcbnew/class_dimension.cpp @@ -89,30 +89,6 @@ void DIMENSION::SetLayer( LAYER_ID aLayer ) } -void DIMENSION::Copy( DIMENSION* source ) -{ - m_Value = source->m_Value; - SetLayer( source->GetLayer() ); - m_Width = source->m_Width; - m_Shape = source->m_Shape; - m_Height = source->m_Height; - m_Unit = source->m_Unit; - SetTimeStamp( GetNewTimeStamp() ); - m_Text.Copy( &source->m_Text ); - - m_crossBarO = source->m_crossBarO; - m_crossBarF = source->m_crossBarF; - m_featureLineGO = source->m_featureLineGO; - m_featureLineGF = source->m_featureLineGF; - m_featureLineDO = source->m_featureLineDO; - m_featureLineDF = source->m_featureLineDF; - m_arrowD1F = source->m_arrowD1F; - m_arrowD2F = source->m_arrowD2F; - m_arrowG1F = source->m_arrowG1F; - m_arrowG2F = source->m_arrowG2F; -} - - void DIMENSION::Move( const wxPoint& offset ) { m_Text.SetTextPosition( m_Text.GetTextPosition() + offset ); diff --git a/pcbnew/class_dimension.h b/pcbnew/class_dimension.h index 93e5e8b776..bb444a63ce 100644 --- a/pcbnew/class_dimension.h +++ b/pcbnew/class_dimension.h @@ -78,7 +78,8 @@ public: DIMENSION( BOARD_ITEM* aParent ); - // Do not create a copy constructor. The one generated by the compiler is adequate. + // Do not create a copy constructor & operator=. + // The ones generated by the compiler are adequate. ~DIMENSION(); @@ -182,8 +183,6 @@ public: TEXTE_PCB& Text() { return m_Text; } TEXTE_PCB& Text() const { return *(const_cast (&m_Text)); } - void Copy( DIMENSION* source ); - void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aColorMode, const wxPoint& offset = ZeroOffset ); diff --git a/pcbnew/class_mire.cpp b/pcbnew/class_mire.cpp index 63c2dc10a0..e447134b6c 100644 --- a/pcbnew/class_mire.cpp +++ b/pcbnew/class_mire.cpp @@ -69,16 +69,6 @@ PCB_TARGET::~PCB_TARGET() { } -void PCB_TARGET::Copy( PCB_TARGET* source ) -{ - m_Layer = source->m_Layer; - m_Width = source->m_Width; - m_Pos = source->m_Pos; - m_Shape = source->m_Shape; - m_Size = source->m_Size; - SetTimeStamp( GetNewTimeStamp() ); -} - /* Draw PCB_TARGET object: 2 segments + 1 circle * The circle radius is half the radius of the target diff --git a/pcbnew/class_mire.h b/pcbnew/class_mire.h index 03bebba9fc..18523b441d 100644 --- a/pcbnew/class_mire.h +++ b/pcbnew/class_mire.h @@ -54,6 +54,9 @@ public: PCB_TARGET( BOARD_ITEM* aParent, int aShape, LAYER_ID aLayer, const wxPoint& aPos, int aSize, int aWidth ); + // Do not create a copy constructor & operator=. + // The ones generated by the compiler are adequate. + ~PCB_TARGET(); void SetPosition( const wxPoint& aPos ) { m_Pos = aPos; } // override @@ -77,8 +80,6 @@ public: void Flip( const wxPoint& aCentre ); - void Copy( PCB_TARGET* source ); - void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode, const wxPoint& offset = ZeroOffset ); diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 97cc3b33fa..05367d656d 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -83,7 +83,6 @@ MODULE::MODULE( const MODULE& aModule ) : { m_Pos = aModule.m_Pos; m_fpid = aModule.m_fpid; - m_Layer = aModule.m_Layer; m_Attributs = aModule.m_Attributs; m_ModuleStatus = aModule.m_ModuleStatus; m_Orient = aModule.m_Orient; @@ -105,35 +104,27 @@ MODULE::MODULE( const MODULE& aModule ) : // Copy reference and value. m_Reference = new TEXTE_MODULE( *aModule.m_Reference ); m_Reference->SetParent( this ); - m_Value = new TEXTE_MODULE( *aModule.m_Value ); m_Value->SetParent( this ); // Copy auxiliary data: Pads for( D_PAD* pad = aModule.m_Pads; pad; pad = pad->Next() ) { - D_PAD* newpad = new D_PAD( *pad ); - assert( newpad->GetNet() == pad->GetNet() ); - newpad->SetParent( this ); - m_Pads.PushBack( newpad ); + Add( new D_PAD( *pad ) ); } // Copy auxiliary data: Drawings for( BOARD_ITEM* item = aModule.m_Drawings; item; item = item->Next() ) { - BOARD_ITEM* newItem; - switch( item->Type() ) { case PCB_MODULE_TEXT_T: case PCB_MODULE_EDGE_T: - newItem = static_cast( item->Clone() ); - newItem->SetParent( this ); - m_Drawings.PushBack( newItem ); + Add( static_cast( item->Clone() ) ); break; default: - wxLogMessage( wxT( "MODULE::Copy() Internal Err: unknown type" ) ); + wxLogMessage( wxT( "Class MODULE copy constructor internal error: unknown type" ) ); break; } } @@ -161,6 +152,76 @@ MODULE::~MODULE() delete m_initial_comments; } + +MODULE& MODULE::operator=( const MODULE& aOther ) +{ + BOARD_ITEM::operator=( aOther ); + + m_Pos = aOther.m_Pos; + m_fpid = aOther.m_fpid; + m_Attributs = aOther.m_Attributs; + m_ModuleStatus = aOther.m_ModuleStatus; + m_Orient = aOther.m_Orient; + m_BoundaryBox = aOther.m_BoundaryBox; + m_CntRot90 = aOther.m_CntRot90; + m_CntRot180 = aOther.m_CntRot180; + m_LastEditTime = aOther.m_LastEditTime; + m_Link = aOther.m_Link; + m_Path = aOther.m_Path; //is this correct behavior? + + m_LocalClearance = aOther.m_LocalClearance; + m_LocalSolderMaskMargin = aOther.m_LocalSolderMaskMargin; + m_LocalSolderPasteMargin = aOther.m_LocalSolderPasteMargin; + m_LocalSolderPasteMarginRatio = aOther.m_LocalSolderPasteMarginRatio; + m_ZoneConnection = aOther.m_ZoneConnection; + m_ThermalWidth = aOther.m_ThermalWidth; + m_ThermalGap = aOther.m_ThermalGap; + + // Copy reference and value + *m_Reference = *aOther.m_Reference; + m_Reference->SetParent( this ); + *m_Value = *aOther.m_Value; + m_Value->SetParent( this ); + + // Copy auxiliary data: Pads + m_Pads.DeleteAll(); + + for( D_PAD* pad = aOther.m_Pads; pad; pad = pad->Next() ) + { + Add( new D_PAD( *pad ) ); + } + + // Copy auxiliary data: Drawings + m_Drawings.DeleteAll(); + + for( BOARD_ITEM* item = aOther.m_Drawings; item; item = item->Next() ) + { + switch( item->Type() ) + { + case PCB_MODULE_TEXT_T: + case PCB_MODULE_EDGE_T: + Add( static_cast( item->Clone() ) ); + break; + + default: + wxLogMessage( wxT( "MODULE::operator=() internal error: unknown type" ) ); + break; + } + } + + // Copy auxiliary data: 3D_Drawings info + m_3D_Drawings.clear(); + m_3D_Drawings = aOther.m_3D_Drawings; + m_Doc = aOther.m_Doc; + m_KeyWord = aOther.m_KeyWord; + + // Ensure auxiliary data is up to date + CalculateBoundingBox(); + + return *this; +} + + /** * Function ClearAllNets * Clear (i.e. force the ORPHANED dummy net info) the net info which @@ -195,85 +256,6 @@ void MODULE::DrawAncre( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset, } -void MODULE::Copy( MODULE* aModule ) -{ - m_Pos = aModule->m_Pos; - m_Layer = aModule->m_Layer; - m_fpid = aModule->m_fpid; - m_Attributs = aModule->m_Attributs; - m_ModuleStatus = aModule->m_ModuleStatus; - m_Orient = aModule->m_Orient; - m_BoundaryBox = aModule->m_BoundaryBox; - m_CntRot90 = aModule->m_CntRot90; - m_CntRot180 = aModule->m_CntRot180; - m_LastEditTime = aModule->m_LastEditTime; - m_Link = aModule->m_Link; - m_Path = aModule->m_Path; //is this correct behavior? - SetTimeStamp( GetNewTimeStamp() ); - - m_LocalClearance = aModule->m_LocalClearance; - m_LocalSolderMaskMargin = aModule->m_LocalSolderMaskMargin; - m_LocalSolderPasteMargin = aModule->m_LocalSolderPasteMargin; - m_LocalSolderPasteMarginRatio = aModule->m_LocalSolderPasteMarginRatio; - m_ZoneConnection = aModule->m_ZoneConnection; - m_ThermalWidth = aModule->m_ThermalWidth; - m_ThermalGap = aModule->m_ThermalGap; - - // Copy reference and value. - m_Reference->Copy( aModule->m_Reference ); - m_Value->Copy( aModule->m_Value ); - - // Copy auxiliary data: Pads - m_Pads.DeleteAll(); - - for( D_PAD* pad = aModule->m_Pads; pad; pad = pad->Next() ) - { - D_PAD* newpad = new D_PAD( this ); - newpad->Copy( pad ); - m_Pads.PushBack( newpad ); - } - - // Copy auxiliary data: Drawings - m_Drawings.DeleteAll(); - - for( BOARD_ITEM* item = aModule->m_Drawings; item; item = item->Next() ) - { - switch( item->Type() ) - { - case PCB_MODULE_TEXT_T: - { - TEXTE_MODULE* textm = new TEXTE_MODULE( this ); - textm->Copy( static_cast( item ) ); - m_Drawings.PushBack( textm ); - break; - } - - case PCB_MODULE_EDGE_T: - { - EDGE_MODULE * edge; - edge = new EDGE_MODULE( this ); - edge->Copy( (EDGE_MODULE*) item ); - m_Drawings.PushBack( edge ); - break; - } - - default: - wxLogMessage( wxT( "MODULE::Copy() Internal Err: unknown type" ) ); - break; - } - } - - // Copy auxiliary data: 3D_Drawings info - m_3D_Drawings.clear(); - m_3D_Drawings = aModule->m_3D_Drawings; - m_Doc = aModule->m_Doc; - m_KeyWord = aModule->m_KeyWord; - - // Ensure auxiliary data is up to date - CalculateBoundingBox(); -} - - void MODULE::Add( BOARD_ITEM* aBoardItem, bool doAppend ) { switch( aBoardItem->Type() ) diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index edbedd6afc..2a0888de97 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -84,6 +84,8 @@ public: ~MODULE(); + MODULE& operator=( const MODULE& aOther ); + static inline bool ClassOf( const EDA_ITEM* aItem ) { return PCB_MODULE_T == aItem->Type(); @@ -92,8 +94,6 @@ public: MODULE* Next() const { return static_cast( Pnext ); } MODULE* Back() const { return static_cast( Pback ); } - void Copy( MODULE* Module ); // Copy structure - /** * Function Add * adds the given item to this MODULE and takes ownership of its memory. diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index ad087792e7..67cd26162e 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -423,41 +423,6 @@ bool D_PAD::IncrementPadName( bool aSkipUnconnectable, bool aFillSequenceGaps ) } -void D_PAD::Copy( D_PAD* source ) -{ - if( source == NULL ) - return; - - m_Pos = source->m_Pos; - m_layerMask = source->m_layerMask; - - m_NumPadName = source->m_NumPadName; - m_netinfo = source->m_netinfo; - m_Drill = source->m_Drill; - m_drillShape = source->m_drillShape; - m_Offset = source->m_Offset; - m_Size = source->m_Size; - m_DeltaSize = source->m_DeltaSize; - m_Pos0 = source->m_Pos0; - m_boundingRadius = source->m_boundingRadius; - m_padShape = source->m_padShape; - m_Attribute = source->m_Attribute; - m_Orient = source->m_Orient; - m_LengthPadToDie = source->m_LengthPadToDie; - m_LocalClearance = source->m_LocalClearance; - m_LocalSolderMaskMargin = source->m_LocalSolderMaskMargin; - m_LocalSolderPasteMargin = source->m_LocalSolderPasteMargin; - m_LocalSolderPasteMarginRatio = source->m_LocalSolderPasteMarginRatio; - m_ZoneConnection = source->m_ZoneConnection; - m_ThermalWidth = source->m_ThermalWidth; - m_ThermalGap = source->m_ThermalGap; - m_padRoundRectRadiusScale = source->m_padRoundRectRadiusScale; - - SetSubRatsnest( 0 ); - SetSubNet( 0 ); -} - - void D_PAD::CopyNetlistSettings( D_PAD* aPad, bool aCopyLocalSettings ) { // Don't do anything foolish like trying to copy to yourself. diff --git a/pcbnew/class_pad.h b/pcbnew/class_pad.h index 12223ab040..0c277b97c6 100644 --- a/pcbnew/class_pad.h +++ b/pcbnew/class_pad.h @@ -82,8 +82,8 @@ public: public: D_PAD( MODULE* parent ); - // Do not create a copy constructor. The one generated by the compiler is adequate. - // D_PAD( const D_PAD& o ); + // Do not create a copy constructor & operator=. + // The ones generated by the compiler are adequate. /* Default layers used for pads, according to the pad type. * this is default values only, they can be changed for a given pad @@ -99,8 +99,6 @@ public: return aItem && PCB_PAD_T == aItem->Type(); } - void Copy( D_PAD* source ); - D_PAD* Next() const { return static_cast( Pnext ); } MODULE* GetParent() const { return (MODULE*) m_Parent; } diff --git a/pcbnew/class_pcb_text.cpp b/pcbnew/class_pcb_text.cpp index c2e5ca6447..27164e3b14 100644 --- a/pcbnew/class_pcb_text.cpp +++ b/pcbnew/class_pcb_text.cpp @@ -60,27 +60,6 @@ TEXTE_PCB:: ~TEXTE_PCB() } -void TEXTE_PCB::Copy( TEXTE_PCB* source ) -{ - m_Parent = source->m_Parent; - Pback = Pnext = NULL; - m_Mirror = source->m_Mirror; - m_Size = source->m_Size; - m_Orient = source->m_Orient; - m_Pos = source->m_Pos; - m_Layer = source->m_Layer; - m_Thickness = source->m_Thickness; - m_Attributs = source->m_Attributs; - m_Italic = source->m_Italic; - m_Bold = source->m_Bold; - m_HJustify = source->m_HJustify; - m_VJustify = source->m_VJustify; - m_MultilineAllowed = source->m_MultilineAllowed; - - m_Text = source->m_Text; -} - - void TEXTE_PCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE DrawMode, const wxPoint& offset ) { diff --git a/pcbnew/class_pcb_text.h b/pcbnew/class_pcb_text.h index b1f1d31e7e..d1120e7ea5 100644 --- a/pcbnew/class_pcb_text.h +++ b/pcbnew/class_pcb_text.h @@ -45,7 +45,8 @@ class TEXTE_PCB : public BOARD_ITEM, public EDA_TEXT public: TEXTE_PCB( BOARD_ITEM* parent ); - // Do not create a copy constructor. The one generated by the compiler is adequate. + // Do not create a copy constructor & operator=. + // The ones generated by the compiler are adequate. ~TEXTE_PCB(); @@ -73,9 +74,6 @@ public: void Flip( const wxPoint& aCentre ); - /* duplicate structure */ - void Copy( TEXTE_PCB* source ); - void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode, const wxPoint& offset = ZeroOffset ); diff --git a/pcbnew/class_text_mod.cpp b/pcbnew/class_text_mod.cpp index adb1f302c3..8f1672143e 100644 --- a/pcbnew/class_text_mod.cpp +++ b/pcbnew/class_text_mod.cpp @@ -124,27 +124,6 @@ void TEXTE_MODULE::Move( const wxPoint& aMoveVector ) } -void TEXTE_MODULE::Copy( TEXTE_MODULE* source ) -{ - if( source == NULL ) - return; - - m_Pos = source->m_Pos; - SetLayer( source->GetLayer() ); - - m_Mirror = source->m_Mirror; - m_NoShow = source->m_NoShow; - m_Type = source->m_Type; - m_Orient = source->m_Orient; - m_Pos0 = source->m_Pos0; - m_Size = source->m_Size; - m_Thickness = source->m_Thickness; - m_Italic = source->m_Italic; - m_Bold = source->m_Bold; - m_Text = source->m_Text; -} - - int TEXTE_MODULE::GetLength() const { return m_Text.Len(); diff --git a/pcbnew/class_text_mod.h b/pcbnew/class_text_mod.h index cb6b0470c1..79edd49c60 100644 --- a/pcbnew/class_text_mod.h +++ b/pcbnew/class_text_mod.h @@ -64,7 +64,8 @@ public: TEXTE_MODULE( MODULE* parent, TEXT_TYPE text_type = TEXT_is_DIVERS ); - // Do not create a copy constructor. The one generated by the compiler is adequate. + // Do not create a copy constructor & operator=. + // The ones generated by the compiler are adequate. ~TEXTE_MODULE(); @@ -112,8 +113,6 @@ public: void SetPos0( const wxPoint& aPos ) { m_Pos0 = aPos; SetDrawCoord(); } const wxPoint& GetPos0() const { return m_Pos0; } - void Copy( TEXTE_MODULE* source ); // copy structure - int GetLength() const; // text length /** diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index 5a464fa797..a03d431932 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -105,6 +105,32 @@ ZONE_CONTAINER::ZONE_CONTAINER( const ZONE_CONTAINER& aZone ) : } +ZONE_CONTAINER& ZONE_CONTAINER::operator=( const ZONE_CONTAINER& aOther ) +{ + BOARD_CONNECTED_ITEM::operator=( aOther ); + + m_Poly->RemoveAllContours(); + m_Poly->Copy( aOther.m_Poly ); // copy outlines + m_CornerSelection = -1; // for corner moving, corner index to drag or -1 if no selection + m_ZoneClearance = aOther.m_ZoneClearance; // clearance value + m_ZoneMinThickness = aOther.m_ZoneMinThickness; + m_FillMode = aOther.m_FillMode; // filling mode (segments/polygons) + m_ArcToSegmentsCount = aOther.m_ArcToSegmentsCount; + m_PadConnection = aOther.m_PadConnection; + m_ThermalReliefGap = aOther.m_ThermalReliefGap; + m_ThermalReliefCopperBridge = aOther.m_ThermalReliefCopperBridge; + m_Poly->SetHatchStyle( aOther.m_Poly->GetHatchStyle() ); + m_Poly->SetHatchPitch( aOther.m_Poly->GetHatchPitch() ); + m_Poly->m_HatchLines = aOther.m_Poly->m_HatchLines; // copy vector + m_FilledPolysList.RemoveAllContours(); + m_FilledPolysList.Append( aOther.m_FilledPolysList ); + m_FillSegmList.clear(); + m_FillSegmList = aOther.m_FillSegmList; + + return *this; +} + + ZONE_CONTAINER::~ZONE_CONTAINER() { delete m_Poly; @@ -751,33 +777,6 @@ void ZONE_CONTAINER::Mirror( const wxPoint& mirror_ref ) } -void ZONE_CONTAINER::Copy( ZONE_CONTAINER* src ) -{ - m_Parent = src->m_Parent; - m_Layer = src->m_Layer; - SetNetCode( src->GetNetCode() ); - SetTimeStamp( src->m_TimeStamp ); - m_Poly->RemoveAllContours(); - m_Poly->Copy( src->m_Poly ); // copy outlines - m_CornerSelection = -1; // For corner moving, corner index to drag, - // or -1 if no selection - m_ZoneClearance = src->m_ZoneClearance; // clearance value - m_ZoneMinThickness = src->m_ZoneMinThickness; - m_FillMode = src->m_FillMode; // Filling mode (segments/polygons) - m_ArcToSegmentsCount = src->m_ArcToSegmentsCount; - m_PadConnection = src->m_PadConnection; - m_ThermalReliefGap = src->m_ThermalReliefGap; - m_ThermalReliefCopperBridge = src->m_ThermalReliefCopperBridge; - m_Poly->SetHatchStyle( src->m_Poly->GetHatchStyle() ); - m_Poly->SetHatchPitch( src->m_Poly->GetHatchPitch() ); - m_Poly->m_HatchLines = src->m_Poly->m_HatchLines; // Copy vector - m_FilledPolysList.RemoveAllContours(); - m_FilledPolysList.Append( src->m_FilledPolysList ); - m_FillSegmList.clear(); - m_FillSegmList = src->m_FillSegmList; -} - - ZoneConnection ZONE_CONTAINER::GetPadConnection( D_PAD* aPad ) const { if( aPad == NULL || aPad->GetZoneConnection() == PAD_ZONE_CONN_INHERITED ) diff --git a/pcbnew/class_zone.h b/pcbnew/class_zone.h index 798e3f2499..76c5ae8baf 100644 --- a/pcbnew/class_zone.h +++ b/pcbnew/class_zone.h @@ -82,6 +82,7 @@ public: ZONE_CONTAINER( BOARD* parent ); ZONE_CONTAINER( const ZONE_CONTAINER& aZone ); + ZONE_CONTAINER& operator=( const ZONE_CONTAINER &aOther ); ~ZONE_CONTAINER(); @@ -104,13 +105,6 @@ public: */ unsigned GetPriority() const { return m_priority; } - /** - * Function copy - * copy useful data from the source. - * flags and linked list pointers are NOT copied - */ - void Copy( ZONE_CONTAINER* src ); - void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ); /** diff --git a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp index e37f4ffb5b..0910078a52 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp @@ -325,10 +325,10 @@ void DIALOG_MODULE_BOARD_EDITOR::InitModeditProperties() } - m_ReferenceCopy = new TEXTE_MODULE( NULL ); - m_ValueCopy = new TEXTE_MODULE( NULL ); - m_ReferenceCopy->Copy( &m_CurrentModule->Reference() ); - m_ValueCopy->Copy( &m_CurrentModule->Value() ); + m_ReferenceCopy = new TEXTE_MODULE( m_CurrentModule->Reference() ); + m_ReferenceCopy->SetParent( m_CurrentModule ); + m_ValueCopy = new TEXTE_MODULE( m_CurrentModule->Value() ); + m_ValueCopy->SetParent( m_CurrentModule ); m_ReferenceCtrl->SetValue( m_ReferenceCopy->GetText() ); m_ValueCtrl->SetValue( m_ValueCopy->GetText() ); @@ -634,8 +634,10 @@ bool DIALOG_MODULE_BOARD_EDITOR::TransferDataFromWindow() } // Init Fields (should be first, because they can be moved or/and flipped later): - m_CurrentModule->Reference().Copy( m_ReferenceCopy ); - m_CurrentModule->Value().Copy( m_ValueCopy ); + TEXTE_MODULE& reference = m_CurrentModule->Reference(); + reference = *m_ReferenceCopy; + TEXTE_MODULE& value = m_CurrentModule->Value(); + value = *m_ValueCopy; // Initialize masks clearances m_CurrentModule->SetLocalClearance( ValueFromTextCtrl( *m_NetClearanceValueCtrl ) ); diff --git a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp index 547a846156..a087650fa2 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp @@ -165,10 +165,10 @@ void DIALOG_MODULE_MODULE_EDITOR::initModeditProperties() m_DocCtrl->SetValue( m_currentModule->GetDescription() ); m_KeywordCtrl->SetValue( m_currentModule->GetKeywords() ); - m_referenceCopy = new TEXTE_MODULE( NULL ); - m_valueCopy = new TEXTE_MODULE( NULL ); - m_referenceCopy->Copy( &m_currentModule->Reference() ); - m_valueCopy->Copy( &m_currentModule->Value() ); + m_referenceCopy = new TEXTE_MODULE( m_currentModule->Reference() ); + m_referenceCopy->SetParent( m_currentModule ); + m_valueCopy = new TEXTE_MODULE( m_currentModule->Value() ); + m_valueCopy->SetParent( m_currentModule ); m_ReferenceCtrl->SetValue( m_referenceCopy->GetText() ); m_ValueCtrl->SetValue( m_valueCopy->GetText() ); m_FootprintNameCtrl->SetValue( m_currentModule->GetFPID().Format() ); @@ -493,8 +493,10 @@ void DIALOG_MODULE_MODULE_EDITOR::OnOkClick( wxCommandEvent& event ) m_currentModule->SetFPID( FPID( footprintName ) ); // Init Fields: - m_currentModule->Reference().Copy( m_referenceCopy ); - m_currentModule->Value().Copy( m_valueCopy ); + TEXTE_MODULE& reference = m_currentModule->Reference(); + reference = *m_referenceCopy; + TEXTE_MODULE& value = m_currentModule->Value(); + value = *m_valueCopy; // Initialize masks clearances m_currentModule->SetLocalClearance( ValueFromTextCtrl( *m_NetClearanceValueCtrl ) ); diff --git a/pcbnew/dialogs/dialog_pad_properties.cpp b/pcbnew/dialogs/dialog_pad_properties.cpp index 3525a7ee8a..34b88478d5 100644 --- a/pcbnew/dialogs/dialog_pad_properties.cpp +++ b/pcbnew/dialogs/dialog_pad_properties.cpp @@ -117,9 +117,9 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, D_PAD* aP m_dummyPad = new D_PAD( (MODULE*) NULL ); if( aPad ) - m_dummyPad->Copy( aPad ); + *m_dummyPad = *aPad; else // We are editing a "master" pad, i.e. a template to create new pads - m_dummyPad->Copy( m_padMaster ); + *m_dummyPad = *m_padMaster; // Show the X and Y axis. It is usefull because pad shape can have an offset // or be a complex shape. diff --git a/pcbnew/edit_pcb_text.cpp b/pcbnew/edit_pcb_text.cpp index 0115be3a19..c9c11e5e7e 100644 --- a/pcbnew/edit_pcb_text.cpp +++ b/pcbnew/edit_pcb_text.cpp @@ -136,7 +136,7 @@ void PCB_EDIT_FRAME::StartMoveTextePcb( TEXTE_PCB* aTextePcb, wxDC* aDC, bool aE // if it is an existing item: prepare a copy to undo/abort command if( !aTextePcb->IsNew() ) - s_TextCopy.Copy( aTextePcb ); + s_TextCopy = *aTextePcb; aTextePcb->SetFlags( IS_MOVED ); SetMsgPanel( aTextePcb ); @@ -192,7 +192,7 @@ TEXTE_PCB* PCB_EDIT_FRAME::CreateTextePcb( wxDC* aDC, TEXTE_PCB* aText ) if( aText ) { - textePcb->Copy( aText ); + *textePcb = *aText; GetBoard()->Add( textePcb ); textePcb->SetFlags( IS_NEW ); if( aDC ) diff --git a/pcbnew/pad_edition_functions.cpp b/pcbnew/pad_edition_functions.cpp index a892f92354..49ced41c22 100644 --- a/pcbnew/pad_edition_functions.cpp +++ b/pcbnew/pad_edition_functions.cpp @@ -52,7 +52,7 @@ void PCB_BASE_FRAME::Export_Pad_Settings( D_PAD* aPad ) D_PAD& mp = GetDesignSettings().m_Pad_Master; // Copy all settings. Some of them are not used, but they break anything - mp.Copy( aPad ); + mp = *aPad; // The pad orientation, for historical reasons is the // pad rotation + parent rotation. // store only the pad rotation. diff --git a/pcbnew/zones_by_polygon.cpp b/pcbnew/zones_by_polygon.cpp index ddb5f48452..2ea54c104f 100644 --- a/pcbnew/zones_by_polygon.cpp +++ b/pcbnew/zones_by_polygon.cpp @@ -108,8 +108,7 @@ void PCB_EDIT_FRAME::Add_Zone_Cutout( wxDC* DC, ZONE_CONTAINER* aZone ) void PCB_EDIT_FRAME::duplicateZone( wxDC* aDC, ZONE_CONTAINER* aZone ) { - ZONE_CONTAINER* newZone = new ZONE_CONTAINER( GetBoard() ); - newZone->Copy( aZone ); + ZONE_CONTAINER* newZone = new ZONE_CONTAINER( *aZone ); newZone->UnFill(); ZONE_SETTINGS zoneSettings; zoneSettings << *aZone; diff --git a/pcbnew/zones_functions_for_undo_redo.cpp b/pcbnew/zones_functions_for_undo_redo.cpp index 65e761f0e0..35d1392453 100644 --- a/pcbnew/zones_functions_for_undo_redo.cpp +++ b/pcbnew/zones_functions_for_undo_redo.cpp @@ -237,7 +237,7 @@ void UpdateCopyOfZonesList( PICKED_ITEMS_LIST& aPickList, wxASSERT_MSG( zcopy != NULL, wxT( "UpdateCopyOfZonesList() error: link = NULL" ) ); - ref->Copy( zcopy ); + *ref = *zcopy; // the copy was deleted; the link does not exists now. aPickList.SetPickedItemLink( NULL, kk ); From b897c5f290cc148049658dfb28b00dadab0cea20 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 13 May 2016 17:31:54 +0200 Subject: [PATCH 05/61] BOARD_ITEM_CONTAINER class. --- include/wxPcbStruct.h | 4 ++ pcbnew/board_item_container.h | 73 +++++++++++++++++++++++++++++++++++ pcbnew/class_board.cpp | 21 ++++------ pcbnew/class_board.h | 40 ++++--------------- pcbnew/class_module.cpp | 21 +++++----- pcbnew/class_module.h | 35 +++-------------- pcbnew/module_editor_frame.h | 3 ++ pcbnew/moduleframe.cpp | 6 +++ pcbnew/pcb_base_edit_frame.h | 8 ++++ pcbnew/pcbframe.cpp | 6 +++ 10 files changed, 132 insertions(+), 85 deletions(-) create mode 100644 pcbnew/board_item_container.h diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 887e7f3075..270643d3e1 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -39,6 +39,7 @@ /* Forward declarations of classes. */ class PCB_SCREEN; class BOARD; +class BOARD_ITEM_CONTAINER; class TEXTE_PCB; class MODULE; class TRACK; @@ -916,6 +917,9 @@ public: ///> @copydoc PCB_BASE_FRAME::SetBoard() void SetBoard( BOARD* aBoard ); + ///> @copydoc PCB_BASE_EDIT_FRAME::GetModel() + BOARD_ITEM_CONTAINER* GetModel() const override; + ///> @copydoc PCB_BASE_FRAME::SetPageSettings() void SetPageSettings( const PAGE_INFO& aPageSettings ); // overload diff --git a/pcbnew/board_item_container.h b/pcbnew/board_item_container.h new file mode 100644 index 0000000000..9e100bd1fa --- /dev/null +++ b/pcbnew/board_item_container.h @@ -0,0 +1,73 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2016 CERN + * @author Maciej Suminski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef BOARD_ITEM_CONTAINER_H +#define BOARD_ITEM_CONTAINER_H + +#include + +enum ADD_MODE { ADD_INSERT, ADD_APPEND }; + +/** + * @brief Abstract interface for BOARD_ITEMs capable of storing other items inside. + * @see MODULE + * @see BOARD + */ +class BOARD_ITEM_CONTAINER : public BOARD_ITEM +{ +public: + BOARD_ITEM_CONTAINER( BOARD_ITEM* aParent, KICAD_T aType ) + : BOARD_ITEM( aParent, aType ) + { + } + + virtual ~BOARD_ITEM_CONTAINER() + { + } + + /** + * @brief Adds an item to the container. + * @param aItem is an item to be added. + * @param aMode decides whether the item is added in the beginning or at the end of the list. + */ + virtual void Add( BOARD_ITEM* aItem, ADD_MODE aMode = ADD_INSERT ) = 0; + + /** + * @brief Removes an item from the container. + * @param aItem is an item to be removed. + */ + virtual void Remove( BOARD_ITEM* aItem ) = 0; + + /** + * @brief Removes an item from the containter and deletes it. + * @param aItem is an item to be deleted. + */ + virtual void Delete( BOARD_ITEM* aItem ) + { + Remove( aItem ); + delete aItem; + } +}; + +#endif /* BOARD_ITEM_CONTAINER_H */ diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 562ae0e2dc..aac91c9ca9 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -67,7 +67,7 @@ wxPoint BOARD_ITEM::ZeroOffset( 0, 0 ); BOARD::BOARD() : - BOARD_ITEM( (BOARD_ITEM*) NULL, PCB_T ), + BOARD_ITEM_CONTAINER( (BOARD_ITEM*) NULL, PCB_T ), m_NetInfo( this ), m_paper( PAGE_INFO::A4 ) { @@ -858,7 +858,7 @@ bool BOARD::IsModuleLayerVisible( LAYER_ID layer ) } -void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) +void BOARD::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode ) { if( aBoardItem == NULL ) { @@ -883,7 +883,7 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) case PCB_TRACE_T: case PCB_VIA_T: - if( aControl & ADD_APPEND ) + if( aMode == ADD_APPEND ) { m_Track.PushBack( (TRACK*) aBoardItem ); } @@ -897,7 +897,7 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) break; case PCB_ZONE_T: - if( aControl & ADD_APPEND ) + if( aMode == ADD_APPEND ) m_Zone.PushBack( (SEGZONE*) aBoardItem ); else m_Zone.PushFront( (SEGZONE*) aBoardItem ); @@ -905,7 +905,7 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) break; case PCB_MODULE_T: - if( aControl & ADD_APPEND ) + if( aMode == ADD_APPEND ) m_Modules.PushBack( (MODULE*) aBoardItem ); else m_Modules.PushFront( (MODULE*) aBoardItem ); @@ -915,14 +915,11 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) m_Status_Pcb = 0; break; - case PCB_MODULE_EDGE_T: - assert( false ); // TODO Orson: I am just checking if it is supposed to be here - case PCB_DIMENSION_T: case PCB_LINE_T: case PCB_TEXT_T: case PCB_TARGET_T: - if( aControl & ADD_APPEND ) + if( aMode == ADD_APPEND ) m_Drawings.PushBack( aBoardItem ); else m_Drawings.PushFront( aBoardItem ); @@ -946,7 +943,7 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) } -BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem ) +void BOARD::Remove( BOARD_ITEM* aBoardItem ) { // find these calls and fix them! Don't send me no stinking' NULL. wxASSERT( aBoardItem ); @@ -959,6 +956,7 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem ) m_NetInfo.RemoveNet( item ); break; } + case PCB_MARKER_T: // find the item in the vector, then remove it @@ -1001,7 +999,6 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem ) case PCB_DIMENSION_T: case PCB_LINE_T: case PCB_TEXT_T: - case PCB_MODULE_EDGE_T: case PCB_TARGET_T: m_Drawings.Remove( aBoardItem ); break; @@ -1012,8 +1009,6 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem ) } m_ratsnest->Remove( aBoardItem ); - - return aBoardItem; } diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index e2a98bd31b..dd4476c267 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -42,6 +42,7 @@ #include #include #include +#include class PCB_BASE_FRAME; @@ -162,7 +163,7 @@ DECL_VEC_FOR_SWIG(TRACKS, TRACK*) * Class BOARD * holds information pertinent to a Pcbnew printed circuit board. */ -class BOARD : public BOARD_ITEM +class BOARD : public BOARD_ITEM_CONTAINER { friend class PCB_EDIT_FRAME; @@ -215,7 +216,7 @@ private: // The default copy constructor & operator= are inadequate, // either write one or do not use it at all BOARD( const BOARD& aOther ) : - BOARD_ITEM( aOther ), m_NetInfo( this ) + BOARD_ITEM_CONTAINER( aOther ), m_NetInfo( this ) { assert( false ); } @@ -270,38 +271,11 @@ public: void SetFileFormatVersionAtLoad( int aVersion ) { m_fileFormatVersionAtLoad = aVersion; } int GetFileFormatVersionAtLoad() const { return m_fileFormatVersionAtLoad; } - /** - * Function Add - * adds the given item to this BOARD and takes ownership of its memory. - * @param aBoardItem The item to add to this board. - * @param aControl An int which can vary how the item is added. - */ - void Add( BOARD_ITEM* aBoardItem, int aControl = 0 ); + ///> @copydoc BOARD_ITEM_CONTAINER::Add() + void Add( BOARD_ITEM* aItem, ADD_MODE aMode = ADD_INSERT ) override; -#define ADD_APPEND 1 ///< aControl flag for Add( aControl ), appends not inserts - - /** - * Function Delete - * removes the given single item from this BOARD and deletes its memory. - * @param aBoardItem The item to remove from this board and delete - */ - void Delete( BOARD_ITEM* aBoardItem ) - { - // developers should run DEBUG versions and fix such calls with NULL - wxASSERT( aBoardItem ); - - if( aBoardItem ) - delete Remove( aBoardItem ); - } - - - /** - * Function Remove - * removes \a aBoardItem from this BOARD and returns it to caller without deleting it. - * @param aBoardItem The item to remove from this board. - * @return BOARD_ITEM* \a aBoardItem which was passed in. - */ - BOARD_ITEM* Remove( BOARD_ITEM* aBoardItem ); + ///> @copydoc BOARD_ITEM_CONTAINER::Remove() + void Remove( BOARD_ITEM* aBoardItem ) override; /** * Function DuplicateAndAddItem diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 05367d656d..a539add30f 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -50,7 +50,7 @@ MODULE::MODULE( BOARD* parent ) : - BOARD_ITEM( (BOARD_ITEM*) parent, PCB_MODULE_T ), + BOARD_ITEM_CONTAINER( (BOARD_ITEM*) parent, PCB_MODULE_T ), m_initial_comments( 0 ) { m_Attributs = MOD_DEFAULT; @@ -79,7 +79,7 @@ MODULE::MODULE( BOARD* parent ) : MODULE::MODULE( const MODULE& aModule ) : - BOARD_ITEM( aModule ) + BOARD_ITEM_CONTAINER( aModule ) { m_Pos = aModule.m_Pos; m_fpid = aModule.m_fpid; @@ -256,7 +256,7 @@ void MODULE::DrawAncre( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset, } -void MODULE::Add( BOARD_ITEM* aBoardItem, bool doAppend ) +void MODULE::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode ) { switch( aBoardItem->Type() ) { @@ -267,14 +267,14 @@ void MODULE::Add( BOARD_ITEM* aBoardItem, bool doAppend ) // no break case PCB_MODULE_EDGE_T: - if( doAppend ) + if( aMode == ADD_APPEND ) m_Drawings.PushBack( aBoardItem ); else m_Drawings.PushFront( aBoardItem ); break; case PCB_PAD_T: - if( doAppend ) + if( aMode == ADD_APPEND ) m_Pads.PushBack( static_cast( aBoardItem ) ); else m_Pads.PushFront( static_cast( aBoardItem ) ); @@ -292,10 +292,11 @@ void MODULE::Add( BOARD_ITEM* aBoardItem, bool doAppend ) } aBoardItem->SetParent( this ); + SetLastEditTime(); } -BOARD_ITEM* MODULE::Remove( BOARD_ITEM* aBoardItem ) +void MODULE::Remove( BOARD_ITEM* aBoardItem ) { switch( aBoardItem->Type() ) { @@ -306,10 +307,12 @@ BOARD_ITEM* MODULE::Remove( BOARD_ITEM* aBoardItem ) // no break case PCB_MODULE_EDGE_T: - return m_Drawings.Remove( aBoardItem ); + m_Drawings.Remove( aBoardItem ); + break; case PCB_PAD_T: - return m_Pads.Remove( static_cast( aBoardItem ) ); + m_Pads.Remove( static_cast( aBoardItem ) ); + break; default: { @@ -319,8 +322,6 @@ BOARD_ITEM* MODULE::Remove( BOARD_ITEM* aBoardItem ) wxFAIL_MSG( msg ); } } - - return NULL; } diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index 2a0888de97..5e21fe645d 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -36,6 +36,7 @@ #include #include // ALL_LAYERS definition. #include +#include #include #include @@ -75,7 +76,7 @@ enum MODULE_ATTR_T }; -class MODULE : public BOARD_ITEM +class MODULE : public BOARD_ITEM_CONTAINER { public: MODULE( BOARD* parent ); @@ -94,35 +95,11 @@ public: MODULE* Next() const { return static_cast( Pnext ); } MODULE* Back() const { return static_cast( Pback ); } - /** - * Function Add - * adds the given item to this MODULE and takes ownership of its memory. - * @param aBoardItem The item to add to this board. - * @param doAppend If true, then append, else insert. - */ - void Add( BOARD_ITEM* aBoardItem, bool doAppend = true ); + ///> @copydoc BOARD_ITEM_CONTAINER::Add() + void Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode = ADD_INSERT ) override; - /** - * Function Delete - * removes the given single item from this MODULE and deletes its memory. - * @param aBoardItem The item to remove from this module and delete - */ - void Delete( BOARD_ITEM* aBoardItem ) - { - // developers should run DEBUG versions and fix such calls with NULL - wxASSERT( aBoardItem ); - - if( aBoardItem ) - delete Remove( aBoardItem ); - } - - /** - * Function Remove - * removes \a aBoardItem from this MODULE and returns it to caller without deleting it. - * @param aBoardItem The item to remove from this module. - * @return BOARD_ITEM* \a aBoardItem which was passed in. - */ - BOARD_ITEM* Remove( BOARD_ITEM* aBoardItem ); + ///> @copydoc BOARD_ITEM_CONTAINER::Remove() + void Remove( BOARD_ITEM* aBoardItem ) override; /** * Function ClearAllNets diff --git a/pcbnew/module_editor_frame.h b/pcbnew/module_editor_frame.h index 9d81f4876c..83ffbade0c 100644 --- a/pcbnew/module_editor_frame.h +++ b/pcbnew/module_editor_frame.h @@ -54,6 +54,9 @@ public: */ static const wxChar* GetFootprintEditorFrameName(); + ///> @copydoc PCB_BASE_FRAME::GetModel() + BOARD_ITEM_CONTAINER* GetModel() const override; + BOARD_DESIGN_SETTINGS& GetDesignSettings() const; // overload PCB_BASE_FRAME, get parent's void SetDesignSettings( const BOARD_DESIGN_SETTINGS& aSettings ); // overload diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index 932e1a2ad5..20de683891 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -350,6 +350,12 @@ FOOTPRINT_EDIT_FRAME::~FOOTPRINT_EDIT_FRAME() } +BOARD_ITEM_CONTAINER* FOOTPRINT_EDIT_FRAME::GetModel() const +{ + return GetBoard()->m_Modules; +} + + const wxString FOOTPRINT_EDIT_FRAME::getLibPath() { try diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index d9cc1cbd6a..3890bb9fc9 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -27,6 +27,8 @@ #include +class BOARD_ITEM_CONTAINER; + /** * Common, abstract interface for edit frames. */ @@ -42,6 +44,12 @@ public: virtual ~PCB_BASE_EDIT_FRAME() {}; + /** + * Function GetModel() + * returns the primary data model. + */ + virtual BOARD_ITEM_CONTAINER* GetModel() const = 0; + /** * Function CreateNewLibrary * prompts user for a library path, then creates a new footprint library at that diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 89405495c6..9724c209b5 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -489,6 +489,12 @@ void PCB_EDIT_FRAME::SetBoard( BOARD* aBoard ) } +BOARD_ITEM_CONTAINER* PCB_EDIT_FRAME::GetModel() const +{ + return m_Pcb; +} + + void PCB_EDIT_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings ) { PCB_BASE_FRAME::SetPageSettings( aPageSettings ); From b0a191ce3d5c0e852562efa88b73d4b508fb85a4 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 18 May 2016 12:17:08 +0200 Subject: [PATCH 06/61] Refactored TestForExistingItem() --- pcbnew/board_undo_redo.cpp | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/pcbnew/board_undo_redo.cpp b/pcbnew/board_undo_redo.cpp index c8d52f7dc5..3a8ad90482 100644 --- a/pcbnew/board_undo_redo.cpp +++ b/pcbnew/board_undo_redo.cpp @@ -120,40 +120,13 @@ using namespace std::placeholders; static bool TestForExistingItem( BOARD* aPcb, BOARD_ITEM* aItem ) { - static std::vector itemsList; + static std::list itemsList; if( aItem == NULL ) // Build list { // Count items to store in itemsList: - int icnt = 0; BOARD_ITEM* item; - - // Count tracks: - for( item = aPcb->m_Track; item != NULL; item = item->Next() ) - icnt++; - - // Count modules: - for( item = aPcb->m_Modules; item != NULL; item = item->Next() ) - icnt++; - - // Count drawings - for( item = aPcb->m_Drawings; item != NULL; item = item->Next() ) - icnt++; - - // Count zones outlines - icnt += aPcb->GetAreaCount(); - - // Count zones segm (now obsolete): - for( item = aPcb->m_Zone; item != NULL; item = item->Next() ) - icnt++; - - NETINFO_LIST& netInfo = aPcb->GetNetInfo(); - - icnt += netInfo.GetNetCount(); - - // Build candidate list: itemsList.clear(); - itemsList.reserve(icnt); // Store items in list: // Append tracks: @@ -176,11 +149,14 @@ static bool TestForExistingItem( BOARD* aPcb, BOARD_ITEM* aItem ) for( item = aPcb->m_Zone; item != NULL; item = item->Next() ) itemsList.push_back( item ); + NETINFO_LIST& netInfo = aPcb->GetNetInfo(); + for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i ) itemsList.push_back( *i ); // Sort list - std::sort( itemsList.begin(), itemsList.end() ); + itemsList.sort(); + return false; } From 1dd43d1d9824dd19894d981fda776608fb86c4a8 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 25 May 2016 11:52:43 +0200 Subject: [PATCH 07/61] Unified undo buffer handling code for PCB & module editor. Replaced UR_MODEDIT with UR_CHANGED. --- common/class_undoredo_container.cpp | 4 - include/class_undoredo_container.h | 2 - include/wxPcbStruct.h | 58 --- pcbnew/CMakeLists.txt | 3 +- pcbnew/array_creator.cpp | 2 +- pcbnew/block_module_editor.cpp | 16 +- .../dialog_edit_module_for_Modedit.cpp | 2 +- ...og_graphic_item_properties_for_Modedit.cpp | 2 +- pcbnew/edgemod.cpp | 8 +- pcbnew/edtxtmod.cpp | 2 +- pcbnew/import_dxf/dialog_dxf_import.cpp | 2 +- pcbnew/modedit.cpp | 14 +- pcbnew/modedit_onclick.cpp | 10 +- pcbnew/modedit_undo_redo.cpp | 176 --------- pcbnew/module_editor_frame.h | 44 --- pcbnew/pcb_base_edit_frame.h | 68 +++- pcbnew/pcbframe.cpp | 4 +- pcbnew/tools/drawing_tool.cpp | 22 +- pcbnew/tools/edit_tool.cpp | 9 +- pcbnew/tools/module_tools.cpp | 6 +- pcbnew/tools/point_editor.cpp | 6 +- pcbnew/{board_undo_redo.cpp => undo_redo.cpp} | 337 ++++++++---------- 22 files changed, 262 insertions(+), 535 deletions(-) delete mode 100644 pcbnew/modedit_undo_redo.cpp rename pcbnew/{board_undo_redo.cpp => undo_redo.cpp} (84%) diff --git a/common/class_undoredo_container.cpp b/common/class_undoredo_container.cpp index 9c71d1ad2d..ada087480e 100644 --- a/common/class_undoredo_container.cpp +++ b/common/class_undoredo_container.cpp @@ -153,10 +153,6 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems() case UR_LIBEDIT: /* Libedit save always a copy of the current item * So, the picker is always owner of the picked item */ - case UR_MODEDIT: /* Specific to the module editor (modedit creates a full - * copy of the current module when changed), - * and the picker is owner of this item - */ delete wrapper.GetItem(); break; diff --git a/include/class_undoredo_container.h b/include/class_undoredo_container.h index 13c9e85b23..ce54b45a8b 100644 --- a/include/class_undoredo_container.h +++ b/include/class_undoredo_container.h @@ -69,8 +69,6 @@ enum UNDO_REDO_T { UR_ROTATED_CLOCKWISE, // Rotated item (clockwise), undo by rotating it UR_FLIPPED, // flipped (board items only), undo by flipping it UR_WIRE_IMAGE, // Specific to Eeschema for handling wires changes. - UR_MODEDIT, // Specific to the module editor (modedit creates a full copy of - // the current module when changed) UR_LIBEDIT, // Specific to the component editor (libedit creates a full copy // of the current component when changed) UR_EXCHANGE_T ///< Use for changing the schematic text type where swapping diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 270643d3e1..4463c40664 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -638,64 +638,6 @@ public: void OnSelectOptionToolbar( wxCommandEvent& event ); void ToolOnRightClick( wxCommandEvent& event ); - /** - * Function SaveCopyInUndoList. - * Creates a new entry in undo list of commands. - * add a picker to handle aItemToCopy - * @param aItemToCopy = the board item modified by the command to undo - * @param aTypeCommand = command type (see enum UNDO_REDO_T) - * @param aTransformPoint = the reference point of the transformation, for - * commands like move - */ - virtual void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy, - UNDO_REDO_T aTypeCommand, - const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ); - - /** - * Function SaveCopyInUndoList (overloaded). - * Creates a new entry in undo list of commands. - * add a list of pickers to handle a list of items - * @param aItemsList = the list of items modified by the command to undo - * @param aTypeCommand = command type (see enum UNDO_REDO_T) - * @param aTransformPoint = the reference point of the transformation, for - * commands like move - */ - virtual void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, - UNDO_REDO_T aTypeCommand, - const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ); - - /** - * Function PutDataInPreviousState - * Used in undo or redo command. - * Put data pointed by List in the previous state, i.e. the state memorized by List - * @param aList = a PICKED_ITEMS_LIST pointer to the list of items to undo/redo - * @param aRedoCommand = a bool: true for redo, false for undo - * @param aRebuildRatsnet = a bool: true to rebuild ratsnest (normal use), false - * to just retrieve last state (used in abort commands that do not need to - * rebuild ratsnest) - */ - void PutDataInPreviousState( PICKED_ITEMS_LIST* aList, - bool aRedoCommand, - bool aRebuildRatsnet = true ); - - /** - * Function RestoreCopyFromRedoList - * Redo the last edition: - * - Save the current board in Undo list - * - Get an old version of the board from Redo list - * @return none - */ - void RestoreCopyFromRedoList( wxCommandEvent& aEvent ); - - /** - * Function RestoreCopyFromUndoList - * Undo the last edition: - * - Save the current board in Redo list - * - Get an old version of the board from Undo list - * @return none - */ - void RestoreCopyFromUndoList( wxCommandEvent& aEvent ); - /* Block operations: */ /** diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index c4aff5177a..21380aaecb 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -190,7 +190,6 @@ set( PCBNEW_CLASS_SRCS array_creator.cpp attribut.cpp board_items_to_polygon_shape_transform.cpp - board_undo_redo.cpp board_netlist_updater.cpp block.cpp block_module_editor.cpp @@ -237,7 +236,6 @@ set( PCBNEW_CLASS_SRCS modedit.cpp modedit_onclick.cpp modeditoptions.cpp - modedit_undo_redo.cpp moduleframe.cpp modules.cpp move-drag_pads.cpp @@ -266,6 +264,7 @@ set( PCBNEW_CLASS_SRCS toolbars_update_user_interface.cpp tracepcb.cpp tr_modif.cpp + undo_redo.cpp xchgmod.cpp zones_convert_brd_items_to_polygons_with_Boost.cpp zones_convert_to_polygons_aux_functions.cpp diff --git a/pcbnew/array_creator.cpp b/pcbnew/array_creator.cpp index 537abea823..4567579751 100644 --- a/pcbnew/array_creator.cpp +++ b/pcbnew/array_creator.cpp @@ -59,7 +59,7 @@ void ARRAY_CREATOR::Invoke() if( isModuleEditor ) { // modedit saves everything upfront - m_parent.SaveCopyInUndoList( getBoard()->m_Modules, UR_MODEDIT ); + m_parent.SaveCopyInUndoList( getBoard()->m_Modules, UR_CHANGED ); } for ( int i = 0; i < numItems; ++i ) diff --git a/pcbnew/block_module_editor.cpp b/pcbnew/block_module_editor.cpp index 1a635e972f..d1ff77b44f 100644 --- a/pcbnew/block_module_editor.cpp +++ b/pcbnew/block_module_editor.cpp @@ -196,7 +196,7 @@ bool FOOTPRINT_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) if( ret == wxID_OK ) { - SaveCopyInUndoList( currentModule, UR_MODEDIT ); + SaveCopyInUndoList( currentModule, UR_CHANGED ); const wxPoint blockCentre = GetScreen()->m_BlockLocate.Centre(); MoveMarkedItemsExactly( currentModule, blockCentre, translation, rotation ); } @@ -213,7 +213,7 @@ bool FOOTPRINT_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) itemsCount = MarkItemsInBloc( currentModule, GetScreen()->m_BlockLocate ); if( itemsCount ) - SaveCopyInUndoList( currentModule, UR_MODEDIT ); + SaveCopyInUndoList( currentModule, UR_CHANGED ); DeleteMarkedItems( currentModule ); break; @@ -226,7 +226,7 @@ bool FOOTPRINT_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) itemsCount = MarkItemsInBloc( currentModule, GetScreen()->m_BlockLocate ); if( itemsCount ) - SaveCopyInUndoList( currentModule, UR_MODEDIT ); + SaveCopyInUndoList( currentModule, UR_CHANGED ); RotateMarkedItems( currentModule, GetScreen()->m_BlockLocate.Centre() ); break; @@ -237,7 +237,7 @@ bool FOOTPRINT_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) itemsCount = MarkItemsInBloc( currentModule, GetScreen()->m_BlockLocate ); if( itemsCount ) - SaveCopyInUndoList( currentModule, UR_MODEDIT ); + SaveCopyInUndoList( currentModule, UR_CHANGED ); MirrorMarkedItems( currentModule, GetScreen()->m_BlockLocate.Centre() ); break; @@ -293,7 +293,7 @@ void FOOTPRINT_EDIT_FRAME::HandleBlockPlace( wxDC* DC ) case BLOCK_MOVE: // Move case BLOCK_PRESELECT_MOVE: // Move with preselection list GetScreen()->m_BlockLocate.ClearItemsList(); - SaveCopyInUndoList( currentModule, UR_MODEDIT ); + SaveCopyInUndoList( currentModule, UR_CHANGED ); MoveMarkedItems( currentModule, GetScreen()->m_BlockLocate.GetMoveVector() ); m_canvas->Refresh( true ); break; @@ -301,7 +301,7 @@ void FOOTPRINT_EDIT_FRAME::HandleBlockPlace( wxDC* DC ) case BLOCK_COPY: // Copy case BLOCK_COPY_AND_INCREMENT: // Copy and increment pad names GetScreen()->m_BlockLocate.ClearItemsList(); - SaveCopyInUndoList( currentModule, UR_MODEDIT ); + SaveCopyInUndoList( currentModule, UR_CHANGED ); CopyMarkedItems( currentModule, GetScreen()->m_BlockLocate.GetMoveVector(), command == BLOCK_COPY_AND_INCREMENT ); break; @@ -313,12 +313,12 @@ void FOOTPRINT_EDIT_FRAME::HandleBlockPlace( wxDC* DC ) case BLOCK_MIRROR_X: case BLOCK_MIRROR_Y: case BLOCK_FLIP: // Mirror by popup menu, from block move - SaveCopyInUndoList( currentModule, UR_MODEDIT ); + SaveCopyInUndoList( currentModule, UR_CHANGED ); MirrorMarkedItems( currentModule, GetScreen()->m_BlockLocate.Centre() ); break; case BLOCK_ROTATE: - SaveCopyInUndoList( currentModule, UR_MODEDIT ); + SaveCopyInUndoList( currentModule, UR_CHANGED ); RotateMarkedItems( currentModule, GetScreen()->m_BlockLocate.Centre() ); break; diff --git a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp index a087650fa2..0d1fe110a8 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp @@ -465,7 +465,7 @@ void DIALOG_MODULE_MODULE_EDITOR::OnOkClick( wxCommandEvent& event ) return; } - m_parent->SaveCopyInUndoList( m_currentModule, UR_MODEDIT ); + m_parent->SaveCopyInUndoList( m_currentModule, UR_CHANGED ); m_currentModule->SetLocked( m_AutoPlaceCtrl->GetSelection() == 1 ); switch( m_AttributsCtrl->GetSelection() ) diff --git a/pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp b/pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp index 17106f65ce..27dc569d7b 100644 --- a/pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp +++ b/pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp @@ -226,7 +226,7 @@ bool DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES::TransferDataFromWindow() return false;; } - m_parent->SaveCopyInUndoList( m_module, UR_MODEDIT ); + m_parent->SaveCopyInUndoList( m_module, UR_CHANGED ); m_module->SetLastEditTime(); wxString msg; diff --git a/pcbnew/edgemod.cpp b/pcbnew/edgemod.cpp index 5dc01b5581..f24dc07b99 100644 --- a/pcbnew/edgemod.cpp +++ b/pcbnew/edgemod.cpp @@ -163,7 +163,7 @@ void FOOTPRINT_EDIT_FRAME::Edit_Edge_Width( EDGE_MODULE* aEdge ) { MODULE* module = GetBoard()->m_Modules; - SaveCopyInUndoList( module, UR_MODEDIT ); + SaveCopyInUndoList( module, UR_CHANGED ); if( aEdge == NULL ) { @@ -225,7 +225,7 @@ void FOOTPRINT_EDIT_FRAME::Edit_Edge_Layer( EDGE_MODULE* aEdge ) if( aEdge && (aEdge->GetLayer() != new_layer) ) { if( ! modified ) // save only once - SaveCopyInUndoList( module, UR_MODEDIT ); + SaveCopyInUndoList( module, UR_CHANGED ); aEdge->SetLayer( new_layer ); modified = true; } @@ -233,7 +233,7 @@ void FOOTPRINT_EDIT_FRAME::Edit_Edge_Layer( EDGE_MODULE* aEdge ) } else if( aEdge->GetLayer() != new_layer ) { - SaveCopyInUndoList( module, UR_MODEDIT ); + SaveCopyInUndoList( module, UR_CHANGED ); aEdge->SetLayer( new_layer ); modified = true; } @@ -330,7 +330,7 @@ EDGE_MODULE* FOOTPRINT_EDIT_FRAME::Begin_Edge_Module( EDGE_MODULE* aEdge, if( aEdge == NULL ) // Start a new edge item { - SaveCopyInUndoList( module, UR_MODEDIT ); + SaveCopyInUndoList( module, UR_CHANGED ); aEdge = new EDGE_MODULE( module ); MoveVector.x = MoveVector.y = 0; diff --git a/pcbnew/edtxtmod.cpp b/pcbnew/edtxtmod.cpp index 733183f96d..07372bf50e 100644 --- a/pcbnew/edtxtmod.cpp +++ b/pcbnew/edtxtmod.cpp @@ -243,7 +243,7 @@ void PCB_BASE_FRAME::PlaceTexteModule( TEXTE_MODULE* Text, wxDC* DC ) if( IsType( FRAME_PCB ) ) SaveCopyInUndoList( Module, UR_CHANGED ); else - SaveCopyInUndoList( Module, UR_MODEDIT ); + SaveCopyInUndoList( Module, UR_CHANGED ); Text->SetOrientation( tmp ); diff --git a/pcbnew/import_dxf/dialog_dxf_import.cpp b/pcbnew/import_dxf/dialog_dxf_import.cpp index 76d84c4d83..2501d1be48 100644 --- a/pcbnew/import_dxf/dialog_dxf_import.cpp +++ b/pcbnew/import_dxf/dialog_dxf_import.cpp @@ -245,7 +245,7 @@ bool InvokeDXFDialogModuleImport( PCB_BASE_FRAME* aCaller, MODULE* aModule ) { const std::list& list = dlg.GetImportedItems(); - aCaller->SaveCopyInUndoList( aModule, UR_MODEDIT ); + aCaller->SaveCopyInUndoList( aModule, UR_CHANGED ); aCaller->OnModify(); std::list::const_iterator it, itEnd; diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index cf0d77ee25..5a53fa1faf 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -651,7 +651,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_POPUP_PCB_DELETE_PAD: - SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); + SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED ); DeletePad( (D_PAD*) GetScreen()->GetCurItem(), false ); SetCurItem( NULL ); m_canvas->MoveCursorToCrossHair(); @@ -674,13 +674,13 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_POPUP_PCB_IMPORT_PAD_SETTINGS: - SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); + SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED ); m_canvas->MoveCursorToCrossHair(); Import_Pad_Settings( (D_PAD*) GetScreen()->GetCurItem(), true ); break; case ID_POPUP_PCB_GLOBAL_IMPORT_PAD_SETTINGS: - SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); + SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED ); // Calls the global change dialog: DlgGlobalChange_PadSettings( (D_PAD*) GetScreen()->GetCurItem() ); m_canvas->MoveCursorToCrossHair(); @@ -707,7 +707,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_POPUP_PCB_DELETE_TEXTMODULE: - SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); + SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED ); DeleteTextModule( static_cast( GetScreen()->GetCurItem() ) ); SetCurItem( NULL ); m_canvas->MoveCursorToCrossHair(); @@ -765,7 +765,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_POPUP_PCB_DELETE_EDGE: - SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); + SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED ); m_canvas->MoveCursorToCrossHair(); RemoveStruct( GetScreen()->GetCurItem() ); SetCurItem( NULL ); @@ -774,7 +774,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_MODEDIT_MODULE_ROTATE: case ID_MODEDIT_MODULE_MIRROR: case ID_MODEDIT_MODULE_MOVE_EXACT: - SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); + SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED ); Transform( (MODULE*) GetScreen()->GetCurItem(), id ); m_canvas->Refresh(); break; @@ -870,7 +870,7 @@ void FOOTPRINT_EDIT_FRAME::moveExact() if( ret == wxID_OK ) { - SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); + SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED ); BOARD_ITEM* item = GetScreen()->GetCurItem(); diff --git a/pcbnew/modedit_onclick.cpp b/pcbnew/modedit_onclick.cpp index 6df77a19e9..97c1c090a5 100644 --- a/pcbnew/modedit_onclick.cpp +++ b/pcbnew/modedit_onclick.cpp @@ -61,7 +61,7 @@ void FOOTPRINT_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) break; case PCB_MODULE_EDGE_T: - SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); + SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED ); Place_EdgeMod( static_cast( item ) ); break; @@ -147,7 +147,7 @@ void FOOTPRINT_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) if( item && item->Type() != PCB_MODULE_T ) // Cannot delete the module itself { - SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); + SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED ); RemoveStruct( item ); SetCurItem( NULL ); } @@ -162,7 +162,7 @@ void FOOTPRINT_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) || (module->GetFlags() != 0) ) break; - SaveCopyInUndoList( module, UR_MODEDIT ); + SaveCopyInUndoList( module, UR_CHANGED ); // set the new relative internal local coordinates of footprint items wxPoint moveVector = module->GetPosition() - GetCrossHairPosition(); @@ -187,14 +187,14 @@ void FOOTPRINT_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) if( GetBoard()->m_Modules == NULL ) break; - SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); + SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED ); CreateTextModule( GetBoard()->m_Modules, DC ); break; case ID_MODEDIT_PAD_TOOL: if( GetBoard()->m_Modules ) { - SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); + SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED ); AddPad( GetBoard()->m_Modules, true ); } diff --git a/pcbnew/modedit_undo_redo.cpp b/pcbnew/modedit_undo_redo.cpp deleted file mode 100644 index 08b8674fdd..0000000000 --- a/pcbnew/modedit_undo_redo.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2007-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include -using namespace std::placeholders; - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - - -void FOOTPRINT_EDIT_FRAME::SaveCopyInUndoList( BOARD_ITEM* aItem, - UNDO_REDO_T aTypeCommand, - const wxPoint& aTransformPoint ) -{ - EDA_ITEM* item; - MODULE* CopyItem; - PICKED_ITEMS_LIST* lastcmd; - - CopyItem = new MODULE( *( (MODULE*) aItem ) ); - CopyItem->SetParent( GetBoard() ); - - lastcmd = new PICKED_ITEMS_LIST(); - ITEM_PICKER wrapper( CopyItem, UR_MODEDIT ); - lastcmd->PushItem( wrapper ); - - GetScreen()->PushCommandToUndoList( lastcmd ); - - /* Clear current flags (which can be temporary set by a current edit command) */ - for( item = CopyItem->GraphicalItems(); item != NULL; item = item->Next() ) - item->ClearFlags(); - - for( D_PAD* pad = CopyItem->Pads(); pad; pad = pad->Next() ) - pad->ClearFlags(); - - CopyItem->Reference().ClearFlags(); - CopyItem->Value().ClearFlags(); - - /* Clear redo list, because after new save there is no redo to do */ - GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList ); -} - - -void FOOTPRINT_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, - UNDO_REDO_T aTypeCommand, - const wxPoint& aTransformPoint ) -{ - assert( aItemsList.GetPickedItem( 0 )->GetParent()->Type() == PCB_MODULE_T ); - MODULE* owner = static_cast( aItemsList.GetPickedItem( 0 )->GetParent() ); - -#ifndef NDEBUG - // All items should have the same parent (MODULE) to make undo/redo entry valid - for( unsigned int i = 0; i < aItemsList.GetCount(); ++i ) - assert( aItemsList.GetPickedItem( i )->GetParent() == owner ); -#endif /* not NDEBUG */ - - SaveCopyInUndoList( owner, aTypeCommand, aTransformPoint ); -} - - -void FOOTPRINT_EDIT_FRAME::RestoreCopyFromRedoList( wxCommandEvent& aEvent ) -{ - if( GetScreen()->GetRedoCommandCount() <= 0 ) - return; - - // Inform tools that undo command was issued - TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL ); - m_toolManager->ProcessEvent( event ); - - // Save current module state in undo list - PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST(); - MODULE* module = GetBoard()->m_Modules.PopFront(); - ITEM_PICKER wrapper( module, UR_MODEDIT ); - KIGFX::VIEW* view = GetGalCanvas()->GetView(); - lastcmd->PushItem( wrapper ); - GetScreen()->PushCommandToUndoList( lastcmd ); - - view->Remove( module ); - module->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) ); - - // Retrieve last module state from undo list - lastcmd = GetScreen()->PopCommandFromRedoList(); - wrapper = lastcmd->PopItem(); - module = (MODULE*) wrapper.GetItem(); - delete lastcmd; - - if( module ) - { - GetBoard()->Add( module ); - GetGalCanvas()->GetView()->Add( module ); - module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1 ) ); - module->ViewUpdate(); - } - - SetCurItem( NULL ); - - OnModify(); - m_canvas->Refresh(); -} - - -void FOOTPRINT_EDIT_FRAME::RestoreCopyFromUndoList( wxCommandEvent& aEvent ) -{ - if( UndoRedoBlocked() ) - return; - - if( GetScreen()->GetUndoCommandCount() <= 0 ) - return; - - // Inform tools that undo command was issued - TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL ); - m_toolManager->ProcessEvent( event ); - - if( UndoRedoBlocked() ) - return; - - // Save current module state in redo list - PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST(); - MODULE* module = GetBoard()->m_Modules.PopFront(); - ITEM_PICKER wrapper( module, UR_MODEDIT ); - KIGFX::VIEW* view = GetGalCanvas()->GetView(); - lastcmd->PushItem( wrapper ); - GetScreen()->PushCommandToRedoList( lastcmd ); - - view->Remove( module ); - module->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) ); - - // Retrieve last module state from undo list - lastcmd = GetScreen()->PopCommandFromUndoList(); - wrapper = lastcmd->PopItem(); - module = (MODULE*) wrapper.GetItem(); - delete lastcmd; - - if( module ) - { - GetBoard()->Add( module, ADD_APPEND ); - view->Add( module ); - module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1 ) ); - module->ViewUpdate(); - } - - SetCurItem( NULL ); - - OnModify(); - m_canvas->Refresh(); -} diff --git a/pcbnew/module_editor_frame.h b/pcbnew/module_editor_frame.h index 83ffbade0c..fb1a7ac799 100644 --- a/pcbnew/module_editor_frame.h +++ b/pcbnew/module_editor_frame.h @@ -270,50 +270,6 @@ public: BOARD_ITEM* ModeditLocateAndDisplay( int aHotKeyCode = 0 ); - /* Undo and redo functions */ - - /** - * Function SaveCopyInUndoList. - * Creates a new entry in undo list of commands. - * add a picker to handle aItemToCopy - * @param aItem = the board item modified by the command to undo - * @param aTypeCommand = command type (see enum UNDO_REDO_T) - * @param aTransformPoint = the reference point of the transformation, for - * commands like move - */ - virtual void SaveCopyInUndoList( BOARD_ITEM* aItem, - UNDO_REDO_T aTypeCommand, - const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ); - - /** - * Function SaveCopyInUndoList (overloaded). - * Creates a new entry in undo list of commands. - * add a list of pickers to handle a list of items - * @param aItemsList = the list of items modified by the command to undo - * @param aTypeCommand = command type (see enum UNDO_REDO_T) - * @param aTransformPoint = the reference point of the transformation, for - * commands like move - */ - virtual void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, - UNDO_REDO_T aTypeCommand, - const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ); - - /** - * Function RestoreCopyFromUndoList - * performs an undo operation on the last edition: - * - Place the current edited library component in Redo list - * - Get old version of the current edited library component - */ - void RestoreCopyFromUndoList( wxCommandEvent& aEvent ); - - /** - * Function RestoreCopyFromRedoList - * performs a redo operation on the the last edition: - * - Place the current edited library component in undo list - * - Get old version of the current edited library component - */ - void RestoreCopyFromRedoList( wxCommandEvent& aEvent ); - /// Return the current library nickname. const wxString GetCurrentLib() const; diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index 3890bb9fc9..7fb313b5fa 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -69,26 +69,62 @@ public: */ virtual void OnEditItemRequest( wxDC* aDC, BOARD_ITEM* aItem ) = 0; + // Undo buffer handling + + /** + * Function SaveCopyInUndoList + * Creates a new entry in undo list of commands. + * add a picker to handle aItemToCopy + * @param aItemToCopy = the board item modified by the command to undo + * @param aTypeCommand = command type (see enum UNDO_REDO_T) + * @param aTransformPoint = the reference point of the transformation, for + * commands like move + */ + void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy, UNDO_REDO_T aTypeCommand, + const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) override; + + /** + * Function SaveCopyInUndoList + * Creates a new entry in undo list of commands. + * add a list of pickers to handle a list of items + * @param aItemsList = the list of items modified by the command to undo + * @param aTypeCommand = command type (see enum UNDO_REDO_T) + * @param aTransformPoint = the reference point of the transformation, + * for commands like move + */ + void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, UNDO_REDO_T aTypeCommand, + const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) override; /** * Function RestoreCopyFromRedoList * Redo the last edition: - * - Save the current data in Undo list - * - Get an old version of the data from Redo list + * - Save the current board in Undo list + * - Get an old version of the board from Redo list + * @return none */ - virtual void RestoreCopyFromRedoList( wxCommandEvent& aEvent ) = 0; + void RestoreCopyFromRedoList( wxCommandEvent& aEvent ); /** * Function RestoreCopyFromUndoList * Undo the last edition: * - Save the current board in Redo list - * - Get an old version of the data from Undo list + * - Get an old version of the board from Undo list + * @return none */ - virtual void RestoreCopyFromUndoList( wxCommandEvent& aEvent ) = 0; + void RestoreCopyFromUndoList( wxCommandEvent& aEvent ); - int GetRotationAngle() const { return m_rotationAngle; } - void SetRotationAngle( int aRotationAngle ); - - bool PostCommandMenuEvent( int evt_type ); + /** + * Function PutDataInPreviousState + * Used in undo or redo command. + * Put data pointed by List in the previous state, i.e. the state memorized by List + * @param aList = a PICKED_ITEMS_LIST pointer to the list of items to undo/redo + * @param aRedoCommand = a bool: true for redo, false for undo + * @param aRebuildRatsnet = a bool: true to rebuild ratsnest (normal use), false + * to just retrieve last state (used in abort commands that do not need to + * rebuild ratsnest) + */ + void PutDataInPreviousState( PICKED_ITEMS_LIST* aList, + bool aRedoCommand, + bool aRebuildRatsnet = true ); /** * Function UndoRedoBlocked @@ -108,6 +144,20 @@ public: m_undoRedoBlocked = aBlock; } + /** + * Function GetRotationAngle() + * Returns the angle used for rotate operations. + */ + int GetRotationAngle() const { return m_rotationAngle; } + + /** + * Function SetRotationAngle() + * Sets the angle used for rotate operations. + */ + void SetRotationAngle( int aRotationAngle ); + + bool PostCommandMenuEvent( int evt_type ); + ///> @copydoc EDA_DRAW_FRAME::UseGalCanvas() void UseGalCanvas( bool aEnable ); diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 9724c209b5..5153f42b9b 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -196,8 +196,8 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) EVT_TOOL( wxID_CUT, PCB_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( wxID_COPY, PCB_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( wxID_PASTE, PCB_EDIT_FRAME::Process_Special_Functions ) - EVT_TOOL( wxID_UNDO, PCB_EDIT_FRAME::RestoreCopyFromUndoList ) - EVT_TOOL( wxID_REDO, PCB_EDIT_FRAME::RestoreCopyFromRedoList ) + EVT_TOOL( wxID_UNDO, PCB_BASE_EDIT_FRAME::RestoreCopyFromUndoList ) + EVT_TOOL( wxID_REDO, PCB_BASE_EDIT_FRAME::RestoreCopyFromRedoList ) EVT_TOOL( wxID_PRINT, PCB_EDIT_FRAME::ToPrinter ) EVT_TOOL( ID_GEN_PLOT_SVG, PCB_EDIT_FRAME::SVG_Print ) EVT_TOOL( ID_GEN_PLOT, PCB_EDIT_FRAME::Process_Special_Functions ) diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index c4ecdc9b0d..c17b9e8849 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -85,7 +85,7 @@ int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent ) if( line ) { m_frame->OnModify(); - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_MODEDIT ); + m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); line->SetParent( m_board->m_Modules ); line->SetLocalCoord(); m_board->m_Modules->GraphicalItems().PushFront( line ); @@ -142,7 +142,7 @@ int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent ) if( circle ) { m_frame->OnModify(); - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_MODEDIT ); + m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); circle->SetParent( m_board->m_Modules ); circle->SetLocalCoord(); m_board->m_Modules->GraphicalItems().PushFront( circle ); @@ -189,7 +189,7 @@ int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent ) if( arc ) { m_frame->OnModify(); - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_MODEDIT ); + m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); arc->SetParent( m_board->m_Modules ); arc->SetLocalCoord(); m_board->m_Modules->GraphicalItems().PushFront( arc ); @@ -237,10 +237,6 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) DIMENSION* dimension = NULL; int maxThickness; - // if one day it is possible to draw dimensions in the footprint editor, - // then hereby I'm letting you know that this tool does not handle UR_MODEDIT undo yet - assert( !m_editModules ); - // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( m_view ); m_view->Add( &preview ); @@ -516,7 +512,7 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) if( m_editModules ) { assert( m_board->m_Modules ); - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_MODEDIT ); + m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); m_board->m_Modules->SetLastEditTime(); for( KIGFX::VIEW_GROUP::const_iter it = preview.Begin(), end = preview.End(); it != end; ++it ) @@ -608,7 +604,7 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) { if( evt->IsClick( BUT_LEFT ) ) { - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_MODEDIT ); + m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); m_board->m_Modules->SetLastEditTime(); // set the new relative internal local coordinates of footprint items @@ -763,7 +759,7 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, l->SetEnd( aGraphic->GetStart() ); l->SetLocalCoord(); - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_MODEDIT ); + m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); m_board->m_Modules->SetLastEditTime(); m_board->m_Modules->GraphicalItems().PushFront( l ); @@ -1032,10 +1028,6 @@ int DRAWING_TOOL::drawZone( bool aKeepout ) DRAWSEGMENT line45; DRAWSEGMENT* helperLine = NULL; // we will need more than one helper line - // if one day it is possible to draw zones in the footprint editor, - // then hereby I'm letting you know that this tool does not handle UR_MODEDIT undo yet - assert( !m_editModules ); - // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( m_view ); m_view->Add( &preview ); @@ -1334,7 +1326,7 @@ int DRAWING_TOOL::placeTextModule() text->ClearFlags(); // Module has to be saved before any modification is made - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_MODEDIT ); + m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); m_board->m_Modules->SetLastEditTime(); m_board->m_Modules->GraphicalItems().PushFront( text ); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 9d3b7dde1b..7104de6bc6 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -715,7 +715,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) // we have a selection to work on now, so start the tool process - PCB_BASE_FRAME* editFrame = getEditFrame(); + PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); editFrame->OnModify(); // prevent other tools making undo points while the duplicate is going on @@ -723,8 +723,9 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) // the original incUndoInhibit(); + // TODO remove the following when undo buffer handles UR_NEW if( m_editModules ) - editFrame->SaveCopyInUndoList( editFrame->GetBoard()->m_Modules, UR_MODEDIT ); + editFrame->SaveCopyInUndoList( editFrame->GetBoard()->m_Modules, UR_CHANGED ); std::vector old_items; @@ -776,6 +777,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) } // record the new items as added + // TODO remove m_editModules condition when undo buffer handles UR_NEW) if( !m_editModules && !selection.Empty() ) { editFrame->SaveCopyInUndoList( selection.items, UR_NEW ); @@ -1007,9 +1009,6 @@ void EDIT_TOOL::processPickedList( const PICKED_ITEMS_LIST* aList ) { case UR_CHANGED: ratsnest->Update( updItem ); - // fall through - - case UR_MODEDIT: updItem->ViewUpdate( KIGFX::VIEW_ITEM::ALL ); break; diff --git a/pcbnew/tools/module_tools.cpp b/pcbnew/tools/module_tools.cpp index 2e5ae48c8f..8ca9030783 100644 --- a/pcbnew/tools/module_tools.cpp +++ b/pcbnew/tools/module_tools.cpp @@ -158,7 +158,7 @@ int MODULE_TOOLS::PlacePad( const TOOL_EVENT& aEvent ) else if( evt->IsClick( BUT_LEFT ) ) { m_frame->OnModify(); - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_MODEDIT ); + m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); m_board->m_Status_Pcb = 0; // I have no clue why, but it is done in the legacy view pad->SetParent( m_board->m_Modules ); @@ -308,7 +308,7 @@ int MODULE_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent ) { // Accept changes m_frame->OnModify(); - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_MODEDIT ); + m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); for( D_PAD* pad : pads ) { @@ -476,7 +476,7 @@ int MODULE_TOOLS::PasteItems( const TOOL_EVENT& aEvent ) else if( evt->IsClick( BUT_LEFT ) ) { m_frame->OnModify(); - m_frame->SaveCopyInUndoList( currentModule, UR_MODEDIT ); + m_frame->SaveCopyInUndoList( currentModule, UR_CHANGED ); m_board->m_Status_Pcb = 0; // I have no clue why, but it is done in the legacy view currentModule->SetLastEditTime(); diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 98d866c0e0..3ea20883d1 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -768,11 +768,7 @@ void POINT_EDITOR::addCorner( const VECTOR2I& aBreakPoint ) PCB_BASE_FRAME* frame = getEditFrame(); frame->OnModify(); - - if( moduleEdge ) - frame->SaveCopyInUndoList( getModel()->m_Modules, UR_MODEDIT ); - else - frame->SaveCopyInUndoList( selection.items, UR_CHANGED ); + frame->SaveCopyInUndoList( selection.items, UR_CHANGED ); DRAWSEGMENT* segment = static_cast( item ); diff --git a/pcbnew/board_undo_redo.cpp b/pcbnew/undo_redo.cpp similarity index 84% rename from pcbnew/board_undo_redo.cpp rename to pcbnew/undo_redo.cpp index 3a8ad90482..3b90c7c88c 100644 --- a/pcbnew/board_undo_redo.cpp +++ b/pcbnew/undo_redo.cpp @@ -3,7 +3,9 @@ * * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016 CERN + * @author Maciej Suminski + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -165,166 +167,42 @@ static bool TestForExistingItem( BOARD* aPcb, BOARD_ITEM* aItem ) } -void BOARD_ITEM::SwapData( BOARD_ITEM* aImage ) +void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( BOARD_ITEM* aItem, UNDO_REDO_T aCommandType, + const wxPoint& aTransformPoint ) { - if( aImage == NULL ) - return; - - // Remark: to create images of edited items to undo, we are using Clone method - // which can duplication of items foe copy, but does not clone all members - // mainly pointers in chain and time stamp, which is set to new, unique value. - // So we have to use the current values of these parameters. - - EDA_ITEM * pnext = Next(); - EDA_ITEM * pback = Back(); - DHEAD* mylist = m_List; - time_t timestamp = GetTimeStamp(); - - switch( Type() ) - { - case PCB_MODULE_T: - std::swap( *((MODULE*) this), *((MODULE*) aImage) ); - break; - - case PCB_ZONE_AREA_T: - std::swap( *((ZONE_CONTAINER*) this), *((ZONE_CONTAINER*) aImage) ); - break; - - case PCB_LINE_T: - std::swap( *((DRAWSEGMENT*) this), *((DRAWSEGMENT*) aImage) ); - break; - - case PCB_TRACE_T: - std::swap( *((TRACK*) this), *((TRACK*) aImage) ); - break; - - case PCB_VIA_T: - std::swap( *((VIA*) this), *((VIA*) aImage) ); - break; - - case PCB_TEXT_T: - std::swap( *((TEXTE_PCB*) this), *((TEXTE_PCB*) aImage) ); - break; - - case PCB_TARGET_T: - std::swap( *((PCB_TARGET*) this), *((PCB_TARGET*) aImage) ); - break; - - case PCB_DIMENSION_T: - std::swap( *((DIMENSION*) this), *((DIMENSION*) aImage) ); - break; - - case PCB_ZONE_T: - default: - wxLogMessage( wxT( "SwapData() error: unexpected type %d" ), Type() ); - break; - } - - // Restore pointers and time stamp, to be sure they are not broken - Pnext = pnext; - Pback = pback; - m_List = mylist; - SetTimeStamp( timestamp ); + PICKED_ITEMS_LIST commandToUndo; + commandToUndo.PushItem( ITEM_PICKER( aItem, aCommandType ) ); + SaveCopyInUndoList( commandToUndo, aCommandType, aTransformPoint ); } -void PCB_EDIT_FRAME::SaveCopyInUndoList( BOARD_ITEM* aItem, - UNDO_REDO_T aCommandType, - const wxPoint& aTransformPoint ) -{ - if( aItem == NULL ) // Nothing to save - return; - - // For texts belonging to modules, we need to save state of the parent module - if( aItem->Type() == PCB_MODULE_TEXT_T ) - { - aItem = aItem->GetParent(); - wxASSERT( aItem->Type() == PCB_MODULE_T ); - aCommandType = UR_CHANGED; - - if( aItem == NULL ) - return; - } - - PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST(); - - commandToUndo->m_TransformPoint = aTransformPoint; - - ITEM_PICKER itemWrapper( aItem, aCommandType ); - - switch( aCommandType ) - { - case UR_CHANGED: // Create a copy of item - if( itemWrapper.GetLink() == NULL ) // When not null, the copy is already done - itemWrapper.SetLink( aItem->Clone() ); - commandToUndo->PushItem( itemWrapper ); - break; - - case UR_NEW: - case UR_DELETED: -#ifdef USE_WX_OVERLAY - // Avoid to redraw when autoplacing - if( aItem->Type() == PCB_MODULE_T ) - if( ((MODULE*)aItem)->GetFlags() & MODULE_to_PLACE ) - break; - m_canvas->Refresh(); -#endif - case UR_MOVED: - case UR_FLIPPED: - case UR_ROTATED: - case UR_ROTATED_CLOCKWISE: - commandToUndo->PushItem( itemWrapper ); - break; - - default: - { - wxString msg; - msg.Printf( wxT( "SaveCopyInUndoList() error (unknown code %X)" ), aCommandType ); - wxMessageBox( msg ); - } - break; - } - - if( commandToUndo->GetCount() ) - { - /* Save the copy in undo list */ - GetScreen()->PushCommandToUndoList( commandToUndo ); - - /* Clear redo list, because after new save there is no redo to do */ - GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList ); - } - else - { - delete commandToUndo; - } -} - - -void PCB_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, - UNDO_REDO_T aTypeCommand, - const wxPoint& aTransformPoint ) +void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, + UNDO_REDO_T aTypeCommand, const wxPoint& aTransformPoint ) { PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST(); commandToUndo->m_TransformPoint = aTransformPoint; // First, filter unnecessary stuff from the list (i.e. for multiple pads / labels modified), - // take the first occurence of the module. - + // take the first occurence of the module (we save copies of modules when one of its subitems + // is changed). for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) { ITEM_PICKER picker = aItemsList.GetItemWrapper(ii); BOARD_ITEM* item = (BOARD_ITEM*) aItemsList.GetPickedItem( ii ); - // For texts belonging to modules, we need to save state of the parent module - if( item->Type() == PCB_MODULE_TEXT_T || item->Type() == PCB_PAD_T ) + // For items belonging to modules, we need to save state of the parent module + if( item->Type() == PCB_MODULE_TEXT_T || item->Type() == PCB_MODULE_EDGE_T + || item->Type() == PCB_PAD_T ) { + // Item to be stored in the undo buffer is the parent module item = item->GetParent(); - wxASSERT( item->Type() == PCB_MODULE_T ); + wxASSERT( item && item->Type() == PCB_MODULE_T ); if( item == NULL ) continue; + // Check if the parent module has already been saved in another entry bool found = false; for( unsigned j = 0; j < commandToUndo->GetCount(); j++ ) @@ -337,11 +215,32 @@ void PCB_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, } if( !found ) - commandToUndo->PushItem( ITEM_PICKER( item, UR_CHANGED ) ); + { + // Create a clean copy of the parent module + MODULE* clone = new MODULE( *static_cast( item ) ); + clone->SetParent( GetBoard() ); + + // Clear current flags (which can be temporary set by a current edit command) + for( EDA_ITEM* item = clone->GraphicalItems(); item; item = item->Next() ) + item->ClearFlags(); + + for( D_PAD* pad = clone->Pads(); pad; pad = pad->Next() ) + pad->ClearFlags(); + + clone->Reference().ClearFlags(); + clone->Value().ClearFlags(); + + ITEM_PICKER picker( item, UR_CHANGED ); + picker.SetLink( clone ); + commandToUndo->PushItem( picker ); + } else + { continue; + } } else { + // Normal case: all other BOARD_ITEMs, are simply copied to the new list commandToUndo->PushItem( picker ); } } @@ -388,7 +287,6 @@ void PCB_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, msg.Printf( wxT( "SaveCopyInUndoList() error (unknown code %X)" ), command ); wxMessageBox( msg ); } - break; } @@ -402,14 +300,70 @@ void PCB_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, /* Clear redo list, because after a new command one cannot redo a command */ GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList ); } - else // Should not occur + else { + // Should not occur + wxASSERT( false ); delete commandToUndo; } } -void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRedoCommand, +void PCB_BASE_EDIT_FRAME::RestoreCopyFromUndoList( wxCommandEvent& aEvent ) +{ + if( UndoRedoBlocked() ) + return; + + if( GetScreen()->GetUndoCommandCount() <= 0 ) + return; + + // Inform tools that undo command was issued + TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL ); + m_toolManager->ProcessEvent( event ); + + // Get the old list + PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromUndoList(); + + // Undo the command + PutDataInPreviousState( List, false ); + + // Put the old list in RedoList + List->ReversePickersListOrder(); + GetScreen()->PushCommandToRedoList( List ); + + OnModify(); + m_canvas->Refresh(); +} + + +void PCB_BASE_EDIT_FRAME::RestoreCopyFromRedoList( wxCommandEvent& aEvent ) +{ + if( UndoRedoBlocked() ) + return; + + if( GetScreen()->GetRedoCommandCount() == 0 ) + return; + + // Inform tools that redo command was issued + TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL ); + m_toolManager->ProcessEvent( event ); + + // Get the old list + PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromRedoList(); + + // Redo the command + PutDataInPreviousState( List, true ); + + // Put the old list in UndoList + List->ReversePickersListOrder(); + GetScreen()->PushCommandToUndoList( List ); + + OnModify(); + m_canvas->Refresh(); +} + + +void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRedoCommand, bool aRebuildRatsnet ) { BOARD_ITEM* item; @@ -449,6 +403,9 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed if( !TestForExistingItem( GetBoard(), item ) ) { + // Checking if it ever happens + wxASSERT_MSG( false, "Item in the undo buffer does not exist" ); + // Remove this non existent item aList->RemovePicker( ii ); ii++; // the current item was removed, ii points now the next item @@ -479,6 +436,9 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed break; } + // It is possible that we are going to replace the selected item, so clear it + SetCurItem( NULL ); + switch( aList->GetPickedItemStatus( ii ) ) { case UR_CHANGED: /* Exchange old and new data for each item */ @@ -516,7 +476,7 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed case UR_NEW: /* new items are deleted */ aList->SetPickedItemStatus( UR_DELETED, ii ); - GetBoard()->Remove( item ); + GetModel()->Remove( item ); if( item->Type() == PCB_MODULE_T ) { @@ -530,7 +490,7 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed case UR_DELETED: /* deleted items are put in List, as new items */ aList->SetPickedItemStatus( UR_NEW, ii ); - GetBoard()->Add( item ); + GetModel()->Add( item ); if( item->Type() == PCB_MODULE_T ) { @@ -600,56 +560,70 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed } -void PCB_EDIT_FRAME::RestoreCopyFromUndoList( wxCommandEvent& aEvent ) +void BOARD_ITEM::SwapData( BOARD_ITEM* aImage ) { - if( UndoRedoBlocked() ) + if( aImage == NULL ) return; - if( GetScreen()->GetUndoCommandCount() <= 0 ) - return; + wxASSERT( Type() == aImage->Type() ); - // Inform tools that undo command was issued - TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL ); - m_toolManager->ProcessEvent( event ); + // Remark: to create images of edited items to undo, we are using Clone method + // which can duplication of items foe copy, but does not clone all members + // mainly pointers in chain and time stamp, which is set to new, unique value. + // So we have to use the current values of these parameters. - /* Get the old list */ - PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromUndoList(); - /* Undo the command */ - PutDataInPreviousState( List, false ); + EDA_ITEM* pnext = Next(); + EDA_ITEM* pback = Back(); + DHEAD* mylist = m_List; + time_t timestamp = GetTimeStamp(); + EDA_ITEM* parent = GetParent(); - /* Put the old list in RedoList */ - List->ReversePickersListOrder(); - GetScreen()->PushCommandToRedoList( List ); + switch( Type() ) + { + case PCB_MODULE_T: + std::swap( *((MODULE*) this), *((MODULE*) aImage) ); + break; - OnModify(); - m_canvas->Refresh(); -} + case PCB_ZONE_AREA_T: + std::swap( *((ZONE_CONTAINER*) this), *((ZONE_CONTAINER*) aImage) ); + break; + case PCB_LINE_T: + std::swap( *((DRAWSEGMENT*) this), *((DRAWSEGMENT*) aImage) ); + break; -void PCB_EDIT_FRAME::RestoreCopyFromRedoList( wxCommandEvent& aEvent ) -{ - if( UndoRedoBlocked() ) - return; + case PCB_TRACE_T: + std::swap( *((TRACK*) this), *((TRACK*) aImage) ); + break; - if( GetScreen()->GetRedoCommandCount() == 0 ) - return; + case PCB_VIA_T: + std::swap( *((VIA*) this), *((VIA*) aImage) ); + break; - // Inform tools that redo command was issued - TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL ); - m_toolManager->ProcessEvent( event ); + case PCB_TEXT_T: + std::swap( *((TEXTE_PCB*)this), *((TEXTE_PCB*)aImage) ); + break; - /* Get the old list */ - PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromRedoList(); + case PCB_TARGET_T: + std::swap( *((PCB_TARGET*)this), *((PCB_TARGET*)aImage) ); + break; - /* Redo the command: */ - PutDataInPreviousState( List, true ); + case PCB_DIMENSION_T: + std::swap( *((DIMENSION*)this), *((DIMENSION*)aImage) ); + break; - /* Put the old list in UndoList */ - List->ReversePickersListOrder(); - GetScreen()->PushCommandToUndoList( List ); + case PCB_ZONE_T: + default: + wxLogMessage( wxT( "SwapData() error: unexpected type %d" ), Type() ); + break; + } - OnModify(); - m_canvas->Refresh(); + // Restore pointers and time stamp, to be sure they are not broken + Pnext = pnext; + Pback = pback; + m_List = mylist; + SetTimeStamp( timestamp ); + SetParent( parent ); } @@ -675,3 +649,4 @@ void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount delete curr_cmd; // Delete command } } + From a5d32bbd63c0fd73f72ed216548f4c6e36715a8b Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 31 May 2016 11:11:17 +0200 Subject: [PATCH 08/61] Moved method descriptions from .cpp to .h. --- pcbnew/class_module.cpp | 26 -------------------------- pcbnew/class_module.h | 7 +++++++ 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index a539add30f..72a92a81c2 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -222,13 +222,6 @@ MODULE& MODULE::operator=( const MODULE& aOther ) } - /** - * Function ClearAllNets - * Clear (i.e. force the ORPHANED dummy net info) the net info which - * depends on a given board for all pads of the footprint. - * This is needed when a footprint is copied between the fp editor and - * the board editor for instance, because net info become fully broken - */ void MODULE::ClearAllNets() { // Force the ORPHANED dummy net info for all pads. @@ -238,10 +231,6 @@ void MODULE::ClearAllNets() } -/* Draw the anchor cross (vertical) - * Must be done after the pads, because drawing the hole will erase overwrite - * every thing already drawn. - */ void MODULE::DrawAncre( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset, int dim_ancre, GR_DRAWMODE draw_mode ) { @@ -499,9 +488,6 @@ const EDA_RECT MODULE::GetBoundingBox() const } -/* Virtual function, from EDA_ITEM. - * display module info on MsgPanel - */ void MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) { int nbpad; @@ -885,11 +871,6 @@ const BOX2I MODULE::ViewBBox() const } -/* Test for validity of the name in a library of the footprint - * ( no spaces, dir separators ... ) - * return true if the given name is valid - * static function - */ bool MODULE::IsLibNameValid( const wxString & aName ) { const wxChar * invalids = StringLibNameInvalidChars( false ); @@ -901,13 +882,6 @@ bool MODULE::IsLibNameValid( const wxString & aName ) } -/* Test for validity of the name of a footprint to be used in a footprint library - * ( no spaces, dir separators ... ) - * param bool aUserReadable = false to get the list of invalid chars - * true to get a readable form (i.e ' ' = 'space' '\t'= 'tab') - * return a constant string giving the list of invalid chars in lib name - * static function - */ const wxChar* MODULE::StringLibNameInvalidChars( bool aUserReadable ) { static const wxChar invalidChars[] = wxT("%$\t \"\\/"); diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index 5e21fe645d..9221d0a22f 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -381,9 +381,16 @@ public: void DrawEdgesOnly( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset, GR_DRAWMODE draw_mode ); + /** + * Function DrawAncre + * Draw the anchor cross (vertical) + * Must be done after the pads, because drawing the hole will erase overwrite + * every thing already drawn. + */ void DrawAncre( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset, int dim_ancre, GR_DRAWMODE draw_mode ); + ///> @copydoc EDA_ITEM::GetMsgPanelInfo void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ); bool HitTest( const wxPoint& aPosition ) const; From b5bfa1405742e10881d6113413c40c60cf15e955 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 3 Jun 2016 15:33:44 +0200 Subject: [PATCH 09/61] Removed unused EDA_ITEM::m_Image field. --- common/base_struct.cpp | 1 - eeschema/operations_on_items_lists.cpp | 2 -- eeschema/schematic_undo_redo.cpp | 2 +- include/base_struct.h | 5 ----- 4 files changed, 1 insertion(+), 9 deletions(-) diff --git a/common/base_struct.cpp b/common/base_struct.cpp index b3d1c134fc..793864ce25 100644 --- a/common/base_struct.cpp +++ b/common/base_struct.cpp @@ -76,7 +76,6 @@ void EDA_ITEM::initVars() Pback = NULL; // Linked list: Link (previous struct) m_Parent = NULL; // Linked list: Link (parent struct) m_List = NULL; // I am not on any list yet - m_Image = NULL; // Link to an image copy for undelete or abort command m_Flags = 0; // flags for editions and other SetTimeStamp( 0 ); // Time stamp used for logical links m_Status = 0; diff --git a/eeschema/operations_on_items_lists.cpp b/eeschema/operations_on_items_lists.cpp index 89346b1958..6f0b790c27 100644 --- a/eeschema/operations_on_items_lists.cpp +++ b/eeschema/operations_on_items_lists.cpp @@ -258,7 +258,5 @@ SCH_ITEM* DuplicateStruct( SCH_ITEM* aDrawStruct, bool aClone ) if( aClone ) NewDrawStruct->SetTimeStamp( aDrawStruct->GetTimeStamp() ); - NewDrawStruct->SetImage( aDrawStruct ); - return NewDrawStruct; } diff --git a/eeschema/schematic_undo_redo.cpp b/eeschema/schematic_undo_redo.cpp index 7c539d0377..1f7da2e205 100644 --- a/eeschema/schematic_undo_redo.cpp +++ b/eeschema/schematic_undo_redo.cpp @@ -102,7 +102,7 @@ /* Used if undo / redo command: - * swap data between Item and its copy, pointed by its .m_Image member + * swap data between Item and its copy, pointed by its picked item link member * swapped data is data modified by edition, so not all values are swapped */ diff --git a/include/base_struct.h b/include/base_struct.h index 88fcf98c49..2990b14f8f 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -179,9 +179,6 @@ protected: /// Flag bits for editing and other uses. STATUS_FLAGS m_Flags; - // Link to an copy of the item use to save the item's state for undo/redo feature. - EDA_ITEM* m_Image; - private: void initVars(); @@ -262,8 +259,6 @@ public: void ClearFlags( STATUS_FLAGS aMask = EDA_ITEM_ALL_FLAGS ) { m_Flags &= ~aMask; } STATUS_FLAGS GetFlags() const { return m_Flags; } - void SetImage( EDA_ITEM* aItem ) { m_Image = aItem; } - /** * Function SetForceVisible * is used to set and cleag force visible flag used to force the item to be drawn From 0bf553b06cd79bb2957c561633070c375463da64 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 3 Jun 2016 17:07:13 +0200 Subject: [PATCH 10/61] Recompute local coordinates when an object is added to MODULE. --- pcbnew/class_module.cpp | 21 +++++++++++++++++++++ pcbnew/import_dxf/dialog_dxf_import.cpp | 2 -- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 72a92a81c2..7ec0d6170d 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -282,6 +282,27 @@ void MODULE::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode ) aBoardItem->SetParent( this ); SetLastEditTime(); + + // Update relative coordinates, it can be done only after there is a parent object assigned + switch( aBoardItem->Type() ) + { + case PCB_MODULE_TEXT_T: + static_cast( aBoardItem )->SetLocalCoord(); + break; + + case PCB_MODULE_EDGE_T: + static_cast( aBoardItem )->SetLocalCoord(); + break; + + case PCB_PAD_T: + static_cast( aBoardItem )->SetLocalCoord(); + break; + + default: + // Huh? It should have been filtered out by the previous switch + assert(false); + break; + } } diff --git a/pcbnew/import_dxf/dialog_dxf_import.cpp b/pcbnew/import_dxf/dialog_dxf_import.cpp index 2501d1be48..ff07ed5d86 100644 --- a/pcbnew/import_dxf/dialog_dxf_import.cpp +++ b/pcbnew/import_dxf/dialog_dxf_import.cpp @@ -264,7 +264,6 @@ bool InvokeDXFDialogModuleImport( PCB_BASE_FRAME* aCaller, MODULE* aModule ) converted = new EDGE_MODULE( aModule ); *static_cast( converted ) = *static_cast( item ); aModule->Add( converted ); - static_cast( converted )->SetLocalCoord(); delete item; break; } @@ -274,7 +273,6 @@ bool InvokeDXFDialogModuleImport( PCB_BASE_FRAME* aCaller, MODULE* aModule ) converted = new TEXTE_MODULE( aModule ); *static_cast( converted ) = *static_cast( item ); aModule->Add( converted ); - static_cast( converted )->SetLocalCoord(); delete item; break; } From c78faec2471bbb57f05f5178b9b819c67643353c Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 7 Jun 2016 16:55:56 +0200 Subject: [PATCH 11/61] SetLastEditTime() upon creating UR_CHANGED entry in undo buffer. --- pcbnew/undo_redo.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pcbnew/undo_redo.cpp b/pcbnew/undo_redo.cpp index 3b90c7c88c..338885908f 100644 --- a/pcbnew/undo_redo.cpp +++ b/pcbnew/undo_redo.cpp @@ -217,7 +217,8 @@ void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsLis if( !found ) { // Create a clean copy of the parent module - MODULE* clone = new MODULE( *static_cast( item ) ); + MODULE* orig = static_cast( item ); + MODULE* clone = new MODULE( *orig ); clone->SetParent( GetBoard() ); // Clear current flags (which can be temporary set by a current edit command) @@ -233,6 +234,8 @@ void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsLis ITEM_PICKER picker( item, UR_CHANGED ); picker.SetLink( clone ); commandToUndo->PushItem( picker ); + + orig->SetLastEditTime(); } else { From ff6bdeee4bb2282eb146a131460293a1315f6ca5 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 8 Jun 2016 11:24:46 +0200 Subject: [PATCH 12/61] Removed a number 'if(m_editModules)' sections from pcbnew tools. --- pcbnew/tools/drawing_tool.cpp | 658 ++++++++++------------------ pcbnew/tools/drawing_tool.h | 18 +- pcbnew/tools/edit_tool.cpp | 42 +- pcbnew/tools/module_tools.cpp | 15 +- pcbnew/tools/pcb_editor_control.cpp | 12 +- pcbnew/tools/pcbnew_control.cpp | 14 +- pcbnew/tools/point_editor.cpp | 34 +- pcbnew/tools/selection_tool.cpp | 9 +- 8 files changed, 267 insertions(+), 535 deletions(-) diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index c17b9e8849..bf08187c2f 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -66,61 +66,35 @@ void DRAWING_TOOL::Reset( RESET_REASON aReason ) m_view = getView(); m_controls = getViewControls(); m_board = getModel(); - m_frame = getEditFrame(); + m_frame = getEditFrame(); } int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent ) { + BOARD_ITEM_CONTAINER* parent = m_frame->GetModel(); + DRAWSEGMENT* line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; boost::optional startingPoint; - if( m_editModules ) + m_frame->SetToolID( m_editModules ? ID_MODEDIT_LINE_TOOL : ID_PCB_ADD_LINE_BUTT, + wxCURSOR_PENCIL, _( "Add graphic line" ) ); + + while( drawSegment( S_SEGMENT, line, startingPoint ) ) { - m_frame->SetToolID( ID_MODEDIT_LINE_TOOL, wxCURSOR_PENCIL, _( "Add graphic line" ) ); - - EDGE_MODULE* line = new EDGE_MODULE( m_board->m_Modules ); - - while( drawSegment( S_SEGMENT, reinterpret_cast( line ), startingPoint ) ) + if( line ) { - if( line ) - { - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); - line->SetParent( m_board->m_Modules ); - line->SetLocalCoord(); - m_board->m_Modules->GraphicalItems().PushFront( line ); - startingPoint = line->GetEnd(); - } - else - { - startingPoint = boost::none; - } + m_frame->OnModify(); + m_frame->SaveCopyInUndoList( line, UR_NEW ); - line = new EDGE_MODULE( m_board->m_Modules ); + parent->Add( line ); + startingPoint = line->GetEnd(); } - } - else // !m_editModules case - { - m_frame->SetToolID( ID_PCB_ADD_LINE_BUTT, wxCURSOR_PENCIL, _( "Add graphic line" ) ); - - DRAWSEGMENT* line = new DRAWSEGMENT; - - while( drawSegment( S_SEGMENT, line, startingPoint ) ) + else { - if( line ) - { - m_board->Add( line ); - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( line, UR_NEW ); - startingPoint = line->GetEnd(); - } - else - { - startingPoint = boost::none; - } - - line = new DRAWSEGMENT; + startingPoint = boost::none; } + + line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; } m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); @@ -131,43 +105,23 @@ int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent ) int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent ) { - if( m_editModules ) + BOARD_ITEM_CONTAINER* parent = m_frame->GetModel(); + DRAWSEGMENT* circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; + + m_frame->SetToolID( m_editModules ? ID_MODEDIT_CIRCLE_TOOL : ID_PCB_CIRCLE_BUTT, + wxCURSOR_PENCIL, _( "Add graphic circle" ) ); + + while( drawSegment( S_CIRCLE, circle ) ) { - m_frame->SetToolID( ID_MODEDIT_CIRCLE_TOOL, wxCURSOR_PENCIL, _( "Add graphic circle" ) ); - - EDGE_MODULE* circle = new EDGE_MODULE( m_board->m_Modules ); - - while( drawSegment( S_CIRCLE, reinterpret_cast( circle ) ) ) + if( circle ) { - if( circle ) - { - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); - circle->SetParent( m_board->m_Modules ); - circle->SetLocalCoord(); - m_board->m_Modules->GraphicalItems().PushFront( circle ); - } + m_frame->OnModify(); + m_frame->SaveCopyInUndoList( circle, UR_NEW ); - circle = new EDGE_MODULE( m_board->m_Modules ); + m_frame->GetModel()->Add( circle ); } - } - else // !m_editModules case - { - m_frame->SetToolID( ID_PCB_CIRCLE_BUTT, wxCURSOR_PENCIL, _( "Add graphic circle" ) ); - DRAWSEGMENT* circle = new DRAWSEGMENT; - - while( drawSegment( S_CIRCLE, circle ) ) - { - if( circle ) - { - m_board->Add( circle ); - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( circle, UR_NEW ); - } - - circle = new DRAWSEGMENT; - } + circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; } m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); @@ -178,43 +132,23 @@ int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent ) int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent ) { - if( m_editModules ) + BOARD_ITEM_CONTAINER* parent = m_frame->GetModel(); + DRAWSEGMENT* arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; + + m_frame->SetToolID( m_editModules ? ID_MODEDIT_ARC_TOOL : ID_PCB_ARC_BUTT, + wxCURSOR_PENCIL, _( "Add graphic arc" ) ); + + while( drawArc( arc ) ) { - m_frame->SetToolID( ID_MODEDIT_ARC_TOOL, wxCURSOR_PENCIL, _( "Add graphic arc" ) ); - - EDGE_MODULE* arc = new EDGE_MODULE( m_board->m_Modules ); - - while( drawArc( reinterpret_cast( arc ) ) ) + if( arc ) { - if( arc ) - { - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); - arc->SetParent( m_board->m_Modules ); - arc->SetLocalCoord(); - m_board->m_Modules->GraphicalItems().PushFront( arc ); - } + m_frame->OnModify(); + m_frame->SaveCopyInUndoList( arc, UR_NEW ); - arc = new EDGE_MODULE( m_board->m_Modules ); + m_frame->GetModel()->Add( arc ); } - } - else // !m_editModules case - { - m_frame->SetToolID( ID_PCB_ARC_BUTT, wxCURSOR_PENCIL, _( "Add graphic arc" ) ); - DRAWSEGMENT* arc = new DRAWSEGMENT; - - while( drawArc( arc ) ) - { - if( arc ) - { - m_board->Add( arc ); - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( arc, UR_NEW ); - } - - arc = new DRAWSEGMENT; - } + arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; } m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); @@ -225,10 +159,147 @@ int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent ) int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) { - if( m_editModules ) - return placeTextModule(); - else - return placeTextPcb(); + BOARD_ITEM* text = NULL; + const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings(); + + // Add a VIEW_GROUP that serves as a preview for the new item + KIGFX::VIEW_GROUP preview( m_view ); + m_view->Add( &preview ); + + m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); + m_controls->ShowCursor( true ); + m_controls->SetSnapping( true ); + // do not capture or auto-pan until we start placing some text + + Activate(); + m_frame->SetToolID( m_editModules ? ID_MODEDIT_TEXT_TOOL : ID_PCB_ADD_TEXT_BUTT, + wxCURSOR_PENCIL, _( "Add text" ) ); + + // Main loop: keep receiving events + while( OPT_TOOL_EVENT evt = Wait() ) + { + VECTOR2I cursorPos = m_controls->GetCursorPosition(); + + if( evt->IsCancel() || evt->IsActivate() ) + { + if( text ) + { + // Delete the old text and have another try + m_frame->GetModel()->Delete( text ); // it was already added by CreateTextPcb() + text = NULL; + + preview.Clear(); + preview.ViewUpdate(); + + m_controls->SetAutoPan( false ); + m_controls->CaptureCursor( false ); + m_controls->ShowCursor( true ); + } + else + break; + + if( evt->IsActivate() ) // now finish unconditionally + break; + } + + else if( text && evt->Category() == TC_COMMAND ) + { + if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) + { + text->Rotate( text->GetPosition(), m_frame->GetRotationAngle() ); + preview.ViewUpdate(); + } + // TODO rotate CCW + else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) + { + text->Flip( text->GetPosition() ); + preview.ViewUpdate(); + } + } + + else if( evt->IsClick( BUT_LEFT ) ) + { + if( !text ) + { + // Init the new item attributes + if( m_editModules ) + { + TEXTE_MODULE* textMod = new TEXTE_MODULE( (MODULE*) m_frame->GetModel() ); + textMod->SetSize( dsnSettings.m_ModuleTextSize ); + textMod->SetThickness( dsnSettings.m_ModuleTextWidth ); + textMod->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); + + DialogEditModuleText textDialog( m_frame, textMod, NULL ); + bool placing = textDialog.ShowModal() && ( textMod->GetText().Length() > 0 ); + + if( placing ) + text = textMod; + else + delete textMod; + } + else + { + assert( !m_editModules ); + text = static_cast( m_frame )->CreateTextePcb( NULL ); + } + + if( text == NULL ) + continue; + + m_controls->CaptureCursor( true ); + m_controls->SetAutoPan( true ); + //m_controls->ShowCursor( false ); + + preview.Add( text ); + } + else + { + //assert( text->GetText().Length() > 0 ); + //assert( text->GetSize().x > 0 && text->GetSize().y > 0 ); + + text->ClearFlags(); + m_view->Add( text ); + + m_frame->OnModify(); + m_frame->SaveCopyInUndoList( text, UR_NEW ); + + if( m_editModules ) + { + m_frame->GetModel()->Add( text ); + } + else + { + // m_board->Add( text ); // it is already added by CreateTextePcb() + } + + preview.Remove( text ); + m_controls->CaptureCursor( false ); + m_controls->SetAutoPan( false ); + m_controls->ShowCursor( true ); + + text = NULL; + } + } + + else if( text && evt->IsMotion() ) + { + text->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); + + // Show a preview of the item + preview.ViewUpdate(); + } + } + + m_controls->ShowCursor( false ); + m_controls->SetSnapping( false ); + m_controls->SetAutoPan( false ); + m_controls->CaptureCursor( false ); + + m_view->Remove( &preview ); + m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); + + return 0; + } @@ -351,13 +422,12 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) assert( dimension->GetOrigin() != dimension->GetEnd() ); assert( dimension->GetWidth() > 0 ); - m_view->Add( dimension ); - m_board->Add( dimension ); - //dimension->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - m_frame->OnModify(); m_frame->SaveCopyInUndoList( dimension, UR_NEW ); + m_view->Add( dimension ); + m_board->Add( dimension ); + preview.Remove( dimension ); } } @@ -431,7 +501,7 @@ int DRAWING_TOOL::DrawKeepout( const TOOL_EVENT& aEvent ) int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) { - if( m_editModules && !m_board->m_Modules ) + if( !m_frame->GetModel() ) return 0; DIALOG_DXF_IMPORT dlg( m_frame ); @@ -509,33 +579,32 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) else if( evt->IsClick( BUT_LEFT ) ) { // Place the drawing - if( m_editModules ) + PICKED_ITEMS_LIST picklist; + BOARD_ITEM_CONTAINER* parent = m_frame->GetModel(); + + for( KIGFX::VIEW_GROUP::const_iter it = preview.Begin(); it != preview.End(); ++it ) { - assert( m_board->m_Modules ); - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); - m_board->m_Modules->SetLastEditTime(); + BOARD_ITEM* item = static_cast( *it ); - for( KIGFX::VIEW_GROUP::const_iter it = preview.Begin(), end = preview.End(); it != end; ++it ) + if( m_editModules ) { - BOARD_ITEM* item = static_cast( *it ); - BOARD_ITEM* converted = NULL; - // Modules use different types for the same things, // so we need to convert imported items to appropriate classes. + BOARD_ITEM* converted = NULL; + switch( item->Type() ) { case PCB_TEXT_T: - converted = new TEXTE_MODULE( m_board->m_Modules ); + converted = new TEXTE_MODULE( (MODULE*) parent ); + // Copy coordinates, layer, etc. - *static_cast( converted ) = *static_cast( item ); - static_cast( converted )->SetLocalCoord(); + *static_cast( converted ) = *static_cast( item ); break; case PCB_LINE_T: - converted = new EDGE_MODULE( m_board->m_Modules ); + converted = new EDGE_MODULE( (MODULE*) parent ); // Copy coordinates, layer, etc. *static_cast( converted ) = *static_cast( item ); - static_cast( converted )->SetLocalCoord(); break; default: @@ -544,33 +613,23 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) } delete item; - - if( converted ) - { - m_board->m_Modules->Add( converted ); - m_view->Add( converted ); - } - } - } - else // !m_editModules case - { - PICKED_ITEMS_LIST picklist; - - for( KIGFX::VIEW_GROUP::const_iter it = preview.Begin(), end = preview.End(); it != end; ++it ) - { - BOARD_ITEM* item = static_cast( *it ); - m_board->Add( item ); - - ITEM_PICKER itemWrapper( item, UR_NEW ); - picklist.PushItem( itemWrapper ); - - m_view->Add( item ); + item = converted; } - m_frame->SaveCopyInUndoList( picklist, UR_NEW ); + ITEM_PICKER itemWrapper( item, UR_NEW ); + picklist.PushItem( itemWrapper ); } m_frame->OnModify(); + m_frame->SaveCopyInUndoList( picklist, UR_NEW ); + + for( KIGFX::VIEW_GROUP::const_iter it = preview.Begin(); it != preview.End(); ++it ) + { + BOARD_ITEM* item = static_cast( *it ); + parent->Add( item ); + m_view->Add( item ); + } + break; } } @@ -604,15 +663,16 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) { if( evt->IsClick( BUT_LEFT ) ) { - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); - m_board->m_Modules->SetLastEditTime(); + MODULE* module = (MODULE*) m_frame->GetModel(); + + m_frame->OnModify(); + m_frame->SaveCopyInUndoList( module, UR_CHANGED ); // set the new relative internal local coordinates of footprint items VECTOR2I cursorPos = m_controls->GetCursorPosition(); - wxPoint moveVector = m_board->m_Modules->GetPosition() - wxPoint( cursorPos.x, cursorPos.y ); - m_board->m_Modules->MoveAnchorPosition( moveVector ); - - m_board->m_Modules->ViewUpdate(); + wxPoint moveVector = module->GetPosition() - wxPoint( cursorPos.x, cursorPos.y ); + module->MoveAnchorPosition( moveVector ); + module->ViewUpdate(); // Usually, we do not need to change twice the anchor position, // so deselect the active tool @@ -747,38 +807,22 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, ( evt->IsDblClick( BUT_LEFT ) && aShape == S_SEGMENT ) ) // User has clicked twice in the same spot { // a clear sign that the current drawing is finished + // Now we have to add the helper line as well if( direction45 ) { - // Now we have to add the helper line as well - if( m_editModules ) - { - EDGE_MODULE* l = new EDGE_MODULE( m_board->m_Modules ); + BOARD_ITEM_CONTAINER* parent = m_frame->GetModel(); + DRAWSEGMENT* l = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) + : new DRAWSEGMENT; - // Copy coordinates, layer, etc. - *static_cast( l ) = line45; - l->SetEnd( aGraphic->GetStart() ); - l->SetLocalCoord(); - - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); - m_board->m_Modules->SetLastEditTime(); - m_board->m_Modules->GraphicalItems().PushFront( l ); - - m_view->Add( l ); - l->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - } - else - { - DRAWSEGMENT* l = static_cast( line45.Clone() ); - l->SetEnd( aGraphic->GetStart() ); - - m_frame->SaveCopyInUndoList( l, UR_NEW ); - m_board->Add( l ); - - m_view->Add( l ); - l->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - } + // Copy coordinates, layer, etc. + *static_cast( l ) = line45; + l->SetEnd( aGraphic->GetStart() ); m_frame->OnModify(); + m_frame->SaveCopyInUndoList( l, UR_NEW ); + + parent->Add( l ); + m_view->Add( l ); } delete aGraphic; @@ -1110,6 +1154,9 @@ int DRAWING_TOOL::drawZone( bool aKeepout ) zone->Outline()->CloseLastContour(); zone->Outline()->RemoveNullSegments(); + m_frame->OnModify(); + m_frame->SaveCopyInUndoList( zone, UR_NEW ); + m_board->Add( zone ); m_view->Add( zone ); @@ -1119,9 +1166,6 @@ int DRAWING_TOOL::drawZone( bool aKeepout ) zone->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_board->GetRatsnest()->Update( zone ); - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( zone, UR_NEW ); - zone = NULL; } else @@ -1238,248 +1282,6 @@ int DRAWING_TOOL::drawZone( bool aKeepout ) } -int DRAWING_TOOL::placeTextModule() -{ - TEXTE_MODULE* text = new TEXTE_MODULE( NULL ); - const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings(); - - assert( m_editModules ); - - // Add a VIEW_GROUP that serves as a preview for the new item - KIGFX::VIEW_GROUP preview( m_view ); - m_view->Add( &preview ); - - m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); - m_controls->ShowCursor( true ); - m_controls->SetSnapping( true ); - // do not capture or auto-pan until we start placing some text - - Activate(); - m_frame->SetToolID( ID_MODEDIT_TEXT_TOOL, wxCURSOR_PENCIL, _( "Add text" ) ); - bool placing = false; - - // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) - { - VECTOR2I cursorPos = m_controls->GetCursorPosition(); - - if( evt->IsCancel() || evt->IsActivate() ) - { - preview.Clear(); - preview.ViewUpdate(); - m_controls->SetAutoPan( false ); - m_controls->CaptureCursor( false ); - m_controls->ShowCursor( true ); - - if( !placing || evt->IsActivate() ) - { - delete text; - break; - } - else - { - placing = false; // start from the beginning - } - } - - else if( text && evt->Category() == TC_COMMAND ) - { - if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) - { - text->Rotate( text->GetPosition(), m_frame->GetRotationAngle() ); - preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - } - else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) - { - text->Flip( text->GetPosition() ); - preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - } - } - - else if( evt->IsClick( BUT_LEFT ) ) - { - if( !placing ) - { - text->SetSize( dsnSettings.m_ModuleTextSize ); - text->SetThickness( dsnSettings.m_ModuleTextWidth ); - text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); - - DialogEditModuleText textDialog( m_frame, text, NULL ); - placing = textDialog.ShowModal() && ( text->GetText().Length() > 0 ); - - if( !placing ) - continue; - - m_controls->CaptureCursor( true ); - m_controls->SetAutoPan( true ); - m_controls->ShowCursor( false ); - text->SetParent( m_board->m_Modules ); // it has to set after the settings dialog - // otherwise the dialog stores it in undo buffer - preview.Add( text ); - } - else - { - assert( text->GetText().Length() > 0 ); - assert( text->GetSize().x > 0 && text->GetSize().y > 0 ); - - text->SetLocalCoord(); - text->ClearFlags(); - - // Module has to be saved before any modification is made - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); - m_board->m_Modules->SetLastEditTime(); - m_board->m_Modules->GraphicalItems().PushFront( text ); - - m_view->Add( text ); - text->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - - m_frame->OnModify(); - - preview.Remove( text ); - m_controls->CaptureCursor( false ); - m_controls->SetAutoPan( false ); - m_controls->ShowCursor( true ); - - text = new TEXTE_MODULE( NULL ); - placing = false; - } - } - - else if( text && evt->IsMotion() ) - { - text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); - - // Show a preview of the item - preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - } - } - - m_controls->ShowCursor( false ); - m_controls->SetSnapping( false ); - m_controls->SetAutoPan( false ); - m_controls->CaptureCursor( false ); - m_view->Remove( &preview ); - - m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); - - return 0; -} - - -int DRAWING_TOOL::placeTextPcb() -{ - TEXTE_PCB* text = NULL; - - assert( !m_editModules ); - - // Add a VIEW_GROUP that serves as a preview for the new item - KIGFX::VIEW_GROUP preview( m_view ); - m_view->Add( &preview ); - - m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); - m_controls->ShowCursor( true ); - m_controls->SetSnapping( true ); - // do not capture or auto-pan until we start placing some text - - Activate(); - m_frame->SetToolID( ID_PCB_ADD_TEXT_BUTT, wxCURSOR_PENCIL, _( "Add text" ) ); - - // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) - { - VECTOR2I cursorPos = m_controls->GetCursorPosition(); - - if( evt->IsCancel() || evt->IsActivate() ) - { - if( text ) - { - // Delete the old text and have another try - m_board->Delete( text ); // it was already added by CreateTextPcb() - text = NULL; - - preview.Clear(); - preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - m_controls->SetAutoPan( false ); - m_controls->CaptureCursor( false ); - m_controls->ShowCursor( true ); - } - else - break; - - if( evt->IsActivate() ) // now finish unconditionally - break; - } - - else if( text && evt->Category() == TC_COMMAND ) - { - if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) - { - text->Rotate( text->GetPosition(), m_frame->GetRotationAngle() ); - preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - } - else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) - { - text->Flip( text->GetPosition() ); - preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - } - } - - else if( evt->IsClick( BUT_LEFT ) ) - { - if( !text ) - { - // Init the new item attributes - text = static_cast( m_frame )->CreateTextePcb( NULL ); - - if( text == NULL ) - continue; - - m_controls->CaptureCursor( true ); - m_controls->SetAutoPan( true ); - preview.Add( text ); - } - else - { - assert( text->GetText().Length() > 0 ); - assert( text->GetSize().x > 0 && text->GetSize().y > 0 ); - - text->ClearFlags(); - m_view->Add( text ); - // m_board->Add( text ); // it is already added by CreateTextePcb() - text->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( text, UR_NEW ); - - preview.Remove( text ); - m_controls->CaptureCursor( false ); - m_controls->SetAutoPan( false ); - - text = NULL; - } - } - - else if( text && evt->IsMotion() ) - { - text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); - - // Show a preview of the item - preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - } - } - - m_controls->ShowCursor( false ); - m_controls->SetSnapping( false ); - m_controls->SetAutoPan( false ); - m_controls->CaptureCursor( false ); - m_view->Remove( &preview ); - - m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); - - return 0; -} - - void DRAWING_TOOL::make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper ) const { VECTOR2I cursorPos = m_controls->GetCursorPosition(); diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index 432da1e64b..828ac17435 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -34,7 +34,7 @@ namespace KIGFX class VIEW_CONTROLS; } class BOARD; -class PCB_EDIT_FRAME; +class PCB_BASE_EDIT_FRAME; class DRAWSEGMENT; /** @@ -156,20 +156,6 @@ private: ///> @param aKeepout decides if the drawn polygon is a zone or a keepout area. int drawZone( bool aKeepout ); - /** - * Function placeTextModule() - * Displays a dialog that allows to input text and its settings and then lets the user decide - * where to place the text in module . - */ - int placeTextModule(); - - /** - * Function placeTextPcb() - * Displays a dialog that allows to input text and its settings and then lets the user decide - * where to place the text in board editor. - */ - int placeTextPcb(); - /** * Function make45DegLine() * Forces a DRAWSEGMENT to be drawn at multiple of 45 degrees. The origin stays the same, @@ -185,7 +171,7 @@ private: KIGFX::VIEW* m_view; KIGFX::VIEW_CONTROLS* m_controls; BOARD* m_board; - PCB_EDIT_FRAME* m_frame; + PCB_BASE_EDIT_FRAME* m_frame; /// Edit module mode flag bool m_editModules; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 7104de6bc6..66e7907456 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -533,10 +533,6 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) // As we are about to remove items, they have to be removed from the selection first m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); - // Save them - for( unsigned int i = 0; i < selectedItems.GetCount(); ++i ) - selectedItems.SetPickedItemStatus( UR_DELETED, i ); - editFrame->OnModify(); editFrame->SaveCopyInUndoList( selectedItems, UR_DELETED ); @@ -588,38 +584,10 @@ void EDIT_TOOL::remove( BOARD_ITEM* aItem ) case TEXTE_MODULE::TEXT_is_DIVERS: // suppress warnings break; } - - if( m_editModules ) - { - MODULE* module = static_cast( aItem->GetParent() ); - module->SetLastEditTime(); - board->m_Status_Pcb = 0; // it is done in the legacy view - aItem->DeleteStructure(); - } - - return; } case PCB_PAD_T: case PCB_MODULE_EDGE_T: - { - MODULE* module = static_cast( aItem->GetParent() ); - module->SetLastEditTime(); - - board->m_Status_Pcb = 0; // it is done in the legacy view - - - if( !m_editModules ) - { - getView()->Remove( aItem ); - board->Remove( aItem ); - } - - aItem->DeleteStructure(); - - return; - } - case PCB_LINE_T: // a segment not on copper layers case PCB_TEXT_T: // a text on a layer case PCB_TRACE_T: // a track segment (segment on a copper layer) @@ -637,7 +605,7 @@ void EDIT_TOOL::remove( BOARD_ITEM* aItem ) } getView()->Remove( aItem ); - board->Remove( aItem ); + getEditFrame()->GetModel()->Remove( aItem ); } @@ -723,10 +691,6 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) // the original incUndoInhibit(); - // TODO remove the following when undo buffer handles UR_NEW - if( m_editModules ) - editFrame->SaveCopyInUndoList( editFrame->GetBoard()->m_Modules, UR_CHANGED ); - std::vector old_items; for( int i = 0; i < selection.Size(); ++i ) @@ -748,6 +712,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) BOARD_ITEM* new_item = NULL; + // TODO move DuplicateAndAddItem() to BOARD_ITEM_CONTAINER? dunno.. if( m_editModules ) new_item = editFrame->GetBoard()->m_Modules->DuplicateAndAddItem( item, increment ); else @@ -777,8 +742,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) } // record the new items as added - // TODO remove m_editModules condition when undo buffer handles UR_NEW) - if( !m_editModules && !selection.Empty() ) + if( !selection.Empty() ) { editFrame->SaveCopyInUndoList( selection.items, UR_NEW ); diff --git a/pcbnew/tools/module_tools.cpp b/pcbnew/tools/module_tools.cpp index 8ca9030783..9848ede18b 100644 --- a/pcbnew/tools/module_tools.cpp +++ b/pcbnew/tools/module_tools.cpp @@ -158,16 +158,10 @@ int MODULE_TOOLS::PlacePad( const TOOL_EVENT& aEvent ) else if( evt->IsClick( BUT_LEFT ) ) { m_frame->OnModify(); - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); + m_frame->SaveCopyInUndoList( pad, UR_NEW ); m_board->m_Status_Pcb = 0; // I have no clue why, but it is done in the legacy view - pad->SetParent( m_board->m_Modules ); - m_board->m_Modules->SetLastEditTime(); - m_board->m_Modules->Pads().PushBack( pad ); - - // Set the relative pad position - // ( pad position for module orient, 0, and relative to the module position) - pad->SetLocalCoord(); + m_frame->GetModel()->Add( pad ); // Take the next available pad number pad->IncrementPadName( true, true ); @@ -479,7 +473,6 @@ int MODULE_TOOLS::PasteItems( const TOOL_EVENT& aEvent ) m_frame->SaveCopyInUndoList( currentModule, UR_CHANGED ); m_board->m_Status_Pcb = 0; // I have no clue why, but it is done in the legacy view - currentModule->SetLastEditTime(); // MODULE::RunOnChildren is infeasible here: we need to create copies of items, do not // directly modify them @@ -487,9 +480,7 @@ int MODULE_TOOLS::PasteItems( const TOOL_EVENT& aEvent ) for( D_PAD* pad = pastedModule->Pads(); pad; pad = pad->Next() ) { D_PAD* clone = static_cast( pad->Clone() ); - currentModule->Add( clone ); - clone->SetLocalCoord(); m_view->Add( clone ); } @@ -503,7 +494,6 @@ int MODULE_TOOLS::PasteItems( const TOOL_EVENT& aEvent ) // Do not add reference/value - convert them to the common type text->SetType( TEXTE_MODULE::TEXT_is_DIVERS ); currentModule->Add( text ); - text->SetLocalCoord(); // Whyyyyyyyyyyyyyyyyyyyyyy?! All other items conform to rotation performed // on its parent module, but texts are so independent.. @@ -512,7 +502,6 @@ int MODULE_TOOLS::PasteItems( const TOOL_EVENT& aEvent ) else if( EDGE_MODULE* edge = dyn_cast( clone ) ) { currentModule->Add( edge ); - edge->SetLocalCoord(); } m_view->Add( clone ); diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 0476bb4614..b5e50f06a4 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -298,14 +298,14 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) } else { + m_frame->OnModify(); + m_frame->SaveCopyInUndoList( module, UR_NEW ); + // Place the selected module module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1 ) ); view->Add( module ); module->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( module, UR_NEW ); - // Remove from preview preview.Remove( module ); module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Remove, &preview, _1 ) ); @@ -454,13 +454,13 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent ) assert( target->GetSize() > 0 ); assert( target->GetWidth() > 0 ); + m_frame->OnModify(); + m_frame->SaveCopyInUndoList( target, UR_NEW ); + view->Add( target ); board->Add( target ); target->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( target, UR_NEW ); - preview.Remove( target ); // Create next PCB_TARGET diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index fae470ed8e..48b06f4e83 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -771,7 +771,6 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent ) int open_ctl; wxString fileName; PICKED_ITEMS_LIST undoListPicker; - ITEM_PICKER picker( NULL, UR_NEW ); PCB_EDIT_FRAME* editFrame = dynamic_cast( m_frame ); BOARD* board = getModel(); @@ -839,8 +838,7 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent ) continue; } - picker.SetItem( track ); - undoListPicker.PushItem( picker ); + undoListPicker.PushItem( ITEM_PICKER( track, UR_NEW ) ); view->Add( track ); m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, track ); } @@ -849,11 +847,11 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent ) for( ; module; module = module->Next() ) { - picker.SetItem( module ); - undoListPicker.PushItem( picker ); + undoListPicker.PushItem( ITEM_PICKER( module, UR_NEW ) ); module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1 ) ); view->Add( module ); + m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, module ); } @@ -861,8 +859,7 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent ) for( ; drawing; drawing = drawing->Next() ) { - picker.SetItem( drawing ); - undoListPicker.PushItem( picker ); + undoListPicker.PushItem( ITEM_PICKER( drawing, UR_NEW ) ); view->Add( drawing ); m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, drawing ); } @@ -870,8 +867,7 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent ) for( ZONE_CONTAINER* zone = board->GetArea( zonescount ); zone; zone = board->GetArea( zonescount ) ) { - picker.SetItem( zone ); - undoListPicker.PushItem( picker ); + undoListPicker.PushItem( ITEM_PICKER( zone, UR_NEW ) ); zonescount++; view->Add( zone ); m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, zone ); diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 3ea20883d1..1ce88ab153 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -292,9 +292,9 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) { if( !modified ) { - // Save items, so changes can be undone editFrame->OnModify(); editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); + controls->ForceCursorPosition( false ); m_original = *m_editedPoint; // Save the original position controls->SetAutoPan( true ); @@ -720,11 +720,12 @@ void POINT_EDITOR::addCorner( const VECTOR2I& aBreakPoint ) { EDA_ITEM* item = m_editPoints->GetParent(); const SELECTION& selection = m_selectionTool->GetSelection(); + PCB_BASE_EDIT_FRAME* frame = getEditFrame(); if( item->Type() == PCB_ZONE_AREA_T ) { - getEditFrame()->OnModify(); - getEditFrame()->SaveCopyInUndoList( selection.items, UR_CHANGED ); + frame->OnModify(); + frame->SaveCopyInUndoList( selection.items, UR_CHANGED ); ZONE_CONTAINER* zone = static_cast( item ); CPolyLine* outline = zone->Outline(); @@ -765,15 +766,14 @@ void POINT_EDITOR::addCorner( const VECTOR2I& aBreakPoint ) else if( item->Type() == PCB_LINE_T || item->Type() == PCB_MODULE_EDGE_T ) { bool moduleEdge = item->Type() == PCB_MODULE_EDGE_T; - PCB_BASE_FRAME* frame = getEditFrame(); - - frame->OnModify(); - frame->SaveCopyInUndoList( selection.items, UR_CHANGED ); DRAWSEGMENT* segment = static_cast( item ); if( segment->GetShape() == S_SEGMENT ) { + ITEM_PICKER old_segment( segment, UR_CHANGED ); + old_segment.SetLink( segment->Clone() ); + SEG seg( segment->GetStart(), segment->GetEnd() ); VECTOR2I nearestPoint = seg.NearestPoint( aBreakPoint ); @@ -786,9 +786,9 @@ void POINT_EDITOR::addCorner( const VECTOR2I& aBreakPoint ) if( moduleEdge ) { EDGE_MODULE* edge = static_cast( segment ); - assert( segment->GetParent()->Type() == PCB_MODULE_T ); + assert( edge->Type() == PCB_MODULE_EDGE_T ); + assert( edge->GetParent()->Type() == PCB_MODULE_T ); newSegment = new EDGE_MODULE( *edge ); - edge->SetLocalCoord(); } else { @@ -799,16 +799,13 @@ void POINT_EDITOR::addCorner( const VECTOR2I& aBreakPoint ) newSegment->SetStart( wxPoint( nearestPoint.x, nearestPoint.y ) ); newSegment->SetEnd( wxPoint( seg.B.x, seg.B.y ) ); - if( moduleEdge ) - { - static_cast( newSegment )->SetLocalCoord(); - getModel()->m_Modules->Add( newSegment ); - } - else - { - getModel()->Add( newSegment ); - } + PICKED_ITEMS_LIST changes; + changes.PushItem( old_segment ); + changes.PushItem( ITEM_PICKER( newSegment, UR_NEW ) ); + frame->OnModify(); + frame->SaveCopyInUndoList( changes, UR_UNSPECIFIED ); + frame->GetModel()->Add( newSegment ); getView()->Add( newSegment ); } } @@ -833,6 +830,7 @@ void POINT_EDITOR::removeCorner( EDIT_POINT* aPoint ) { frame->OnModify(); frame->SaveCopyInUndoList( selection.items, UR_CHANGED ); + outline->DeleteCorner( i ); setEditedPoint( NULL ); break; diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index d08ca74c50..4f81e41612 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -360,12 +360,9 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag ) GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide(); GENERAL_COLLECTOR collector; - if( m_editModules ) - collector.Collect( getModel(), GENERAL_COLLECTOR::ModuleItems, - wxPoint( aWhere.x, aWhere.y ), guide ); - else - collector.Collect( getModel(), GENERAL_COLLECTOR::AllBoardItems, - wxPoint( aWhere.x, aWhere.y ), guide ); + collector.Collect( getModel(), + m_editModules ? GENERAL_COLLECTOR::ModuleItems : GENERAL_COLLECTOR::AllBoardItems, + wxPoint( aWhere.x, aWhere.y ), guide ); bool anyCollected = collector.GetCount() != 0; From 9588a7974c1718ee5c384e823de9f48fe4568738 Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Tue, 10 May 2016 17:57:21 +0200 Subject: [PATCH 13/61] Added classes COMMIT & BOARD_COMMIT. --- common/CMakeLists.txt | 1 + common/commit.cpp | 97 ++++++++++++++++++ common/commit.h | 113 +++++++++++++++++++++ pcbnew/CMakeLists.txt | 1 + pcbnew/board_commit.cpp | 215 ++++++++++++++++++++++++++++++++++++++++ pcbnew/board_commit.h | 48 +++++++++ 6 files changed, 475 insertions(+) create mode 100644 common/commit.cpp create mode 100644 common/commit.h create mode 100644 pcbnew/board_commit.cpp create mode 100644 pcbnew/board_commit.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 612c817bed..2791ae821d 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -203,6 +203,7 @@ set( COMMON_SRCS class_plotter.cpp class_undoredo_container.cpp colors.cpp + commit.cpp common.cpp common_plot_functions.cpp common_plotHPGL_functions.cpp diff --git a/common/commit.cpp b/common/commit.cpp new file mode 100644 index 0000000000..7f94f90375 --- /dev/null +++ b/common/commit.cpp @@ -0,0 +1,97 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2016 CERN + * @author Tomasz Wlostowski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include + +#include + +COMMIT::COMMIT() +{ + m_committed = false; +} + + +COMMIT::~COMMIT() +{ + if( !m_committed ) + { + BOOST_FOREACH( COMMIT_LINE& ent, m_changes ) + { + if( ent.m_copy ) + delete ent.m_copy; + } + } +} + + +void COMMIT::makeEntry( EDA_ITEM* aItem, CHANGE_TYPE type, bool saveCopy ) +{ + COMMIT_LINE ent; + + ent.m_item = aItem; + ent.m_type = type; + ent.m_copy = saveCopy ? (EDA_ITEM*) aItem->Clone() : NULL; + + m_changedItems.insert( aItem ); + m_changes.push_back( ent ); +} + + +COMMIT& COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ) +{ + switch( aChangeType ) + { + case CHT_ADD: + assert( m_changedItems.find( aItem ) == m_changedItems.end() ); + makeEntry( aItem, CHT_ADD, false ); + return *this; + + case CHT_REMOVE: + makeEntry( aItem, CHT_REMOVE, false ); + return *this; + + case CHT_MODIFY: + { + EDA_ITEM* parent = parentObject( aItem ); + + if( m_changedItems.find( parent ) != m_changedItems.end() ) + return *this; // item already modifed once + + makeEntry( aItem, CHT_MODIFY, true ); + return *this; + } + + default: + assert( false ); + } +} + + +void COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, CHANGE_TYPE aChangeType ) +{ + for( int i = 0; i < aItems.GetCount(); i++ ) + Stage( aItems.GetPickedItem( i ), aChangeType ); +} + diff --git a/common/commit.h b/common/commit.h new file mode 100644 index 0000000000..4256c7f8a2 --- /dev/null +++ b/common/commit.h @@ -0,0 +1,113 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2016 CERN + * @author Tomasz Wlostowski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __COMMIT_H +#define __COMMIT_H + +#include +#include +#include + +#include + +class PICKED_ITEMS_LIST; + +/** + * Class COMMIT + * + * Represents a set of changes (additions, deletions or modifications) + * of a data model (e.g. the BOARD) class. + * + * The class can be used to propagate changes to subscribed objects (e.g. views, ratsnest), + * and automatically create undo/redo points. + */ +class COMMIT +{ +public: + ///> types of changes. + enum CHANGE_TYPE { + CHT_ADD = 0, + CHT_REMOVE = 1, + CHT_MODIFY = 2 + }; + + COMMIT(); + virtual ~COMMIT(); + + ///> Adds a new item to the model + COMMIT& Add( EDA_ITEM* aItem ) + { + return Stage( aItem, CHT_ADD ); + } + + ///> Removes a new item from the model + COMMIT& Remove( EDA_ITEM* aItem ) + { + return Stage( aItem, CHT_REMOVE ); + } + + ///> Modifies a given item in the model. + ///> Must be called before modification is performed. + COMMIT& Modify( EDA_ITEM* aItem ) + { + return Stage( aItem, CHT_MODIFY ); + } + + ///> Adds a change of the item aItem of type aChangeType to the change list. + virtual COMMIT& Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ); + + void Stage( std::vector& container, CHANGE_TYPE aChangeType ) + { + BOOST_FOREACH( EDA_ITEM* item, container ) + { + Stage( item, aChangeType ); + } + } + + void Stage( const PICKED_ITEMS_LIST& aItems, CHANGE_TYPE aChangeType ); + + ///> Executes the changes. + virtual void Push( const wxString& aMessage ) = 0; + + ///> Revertes the commit by restoring the modifed items state. + virtual void Revert() = 0; + +protected: + struct COMMIT_LINE + { + EDA_ITEM *m_item; + EDA_ITEM *m_copy; + CHANGE_TYPE m_type; + }; + + virtual void makeEntry( EDA_ITEM* aItem, CHANGE_TYPE type, bool saveCopy ); + virtual EDA_ITEM* parentObject( EDA_ITEM* aItem ) const = 0; + + bool m_committed; + + std::set m_changedItems; + std::vector m_changes; +}; + +#endif diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 21380aaecb..a2e094b487 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -182,6 +182,7 @@ set( PCBNEW_AUTOROUTER_SRCS ) set( PCBNEW_CLASS_SRCS + board_commit.cpp tool_modview.cpp modview_frame.cpp pcbframe.cpp diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp new file mode 100644 index 0000000000..0fa58381a5 --- /dev/null +++ b/pcbnew/board_commit.cpp @@ -0,0 +1,215 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2016 CERN + * @author Tomasz Wlostowski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +BOARD_COMMIT::BOARD_COMMIT( PCB_TOOL* aTool ) +{ + m_tool = aTool; +} + + +BOARD_COMMIT::~BOARD_COMMIT() +{ +} + + +void BOARD_COMMIT::Push( const wxString& aMessage ) +{ + // Objects potentially interested in changes: + PICKED_ITEMS_LIST undoList; + TOOL_MANAGER* toolMgr = m_tool->GetManager(); + KIGFX::VIEW* view = toolMgr->GetView(); + BOARD* board = (BOARD*) toolMgr->GetModel(); + PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) toolMgr->GetEditFrame(); + RN_DATA* ratsnest = board->GetRatsnest(); + + bool editModules = m_tool->EditingModules(); + + // Module items need to be saved in the undo buffer before modification + if( editModules ) + { + frame->SaveCopyInUndoList( board->m_Modules, UR_CHANGED ); + } + + BOOST_FOREACH( COMMIT_LINE& ent, m_changes ) + { + BOARD_ITEM* boardItem = static_cast( ent.m_item ); + + switch( ent.m_type ) + { + case CHT_ADD: + { + if( !editModules ) + { + ITEM_PICKER itemWrapper( boardItem, UR_NEW ); + undoList.PushItem( itemWrapper ); + board->Add( boardItem ); + } + else + { + board->m_Modules->Add( boardItem ); + } + + if( boardItem->Type() == PCB_MODULE_T ) + { + MODULE* mod = static_cast( boardItem ); + mod->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) ); + } + + view->Add( boardItem ); + break; + } + + case CHT_REMOVE: + { + if( !editModules ) + { + ITEM_PICKER itemWrapper( boardItem, UR_DELETED ); + undoList.PushItem( itemWrapper ); + board->Remove( boardItem ); + } else { + board->m_Modules->Remove( boardItem ); + } + + if(boardItem->Type() == PCB_MODULE_T ) + { + MODULE* mod = static_cast( boardItem ); + mod->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) ); + } + + view->Remove( boardItem ); + break; + } + + case CHT_MODIFY: + { + if( !editModules ) + { + ITEM_PICKER itemWrapper( boardItem, UR_CHANGED ); + itemWrapper.SetLink( ent.m_copy ); + undoList.PushItem( itemWrapper ); + } + + if( boardItem->Type() == PCB_MODULE_T ) + { + MODULE* mod = static_cast( boardItem ); + //mod->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) ); + mod->RunOnChildren( boost::bind( &RN_DATA::Update, ratsnest, _1 ) ); + } + + boardItem->ViewUpdate( KIGFX::VIEW_ITEM::ALL ); + ratsnest->Update( boardItem ); + break; + } + + default: + break; + } + } + + if( !editModules ) + frame->SaveCopyInUndoList( undoList, UR_UNSPECIFIED ); + + frame->OnModify(); + ratsnest->Recalculate(); + + m_committed = true; +} + + +EDA_ITEM* BOARD_COMMIT::parentObject( EDA_ITEM* aItem ) const +{ + switch( aItem->Type() ) + { + case PCB_PAD_T: + case PCB_MODULE_EDGE_T: + case PCB_MODULE_TEXT_T: + return aItem->GetParent(); + default: + return aItem; + } + + return aItem; +} + + +void BOARD_COMMIT::Revert() +{ + #if 0 + PICKED_ITEMS_LIST undoList; + KIGFX::VIEW* view = m_toolMgr->GetView(); + BOARD *board = (BOARD*) m_toolMgr->GetModel(); + PCB_EDIT_FRAME *frame = (PCB_EDIT_FRAME*) m_toolMgr->GetEditFrame(); + + + BOOST_FOREACH( COMMIT_LINE& ent, m_changes ) + { + BOARD_ITEM *item = static_cast (ent.m_item); + BOARD_ITEM *copy = static_cast (ent.m_copy); + + if(ent.m_type == CHT_MODIFY) + { + printf("revert %p\n", item ); + RN_DATA *ratsnest = board->GetRatsnest(); + + if( item->Type() == PCB_MODULE_T ) + { + MODULE* oldModule = static_cast( item ); + oldModule->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) ); + } + view->Remove( item ); + ratsnest->Remove( static_cast ( item ) ); + + item->SwapData( copy ); + + // Update all pads/drawings/texts, as they become invalid + // for the VIEW after SwapData() called for modules + if( item->Type() == PCB_MODULE_T ) + { + MODULE* newModule = static_cast( item ); + newModule->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) ); + } + view->Add( item ); + ratsnest->Add( item ); + + item->ClearFlags( SELECTED ); + + break; + } + } + #endif +} + diff --git a/pcbnew/board_commit.h b/pcbnew/board_commit.h new file mode 100644 index 0000000000..84d87f79ef --- /dev/null +++ b/pcbnew/board_commit.h @@ -0,0 +1,48 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2016 CERN + * @author Tomasz Wlostowski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __BOARD_COMMIT_H +#define __BOARD_COMMIT_H + +#include + +class BOARD_ITEM; +class PICKED_ITEMS_LIST; +class PCB_TOOL; + +class BOARD_COMMIT : public COMMIT +{ +public: + BOARD_COMMIT( PCB_TOOL* aTool ); + virtual ~BOARD_COMMIT(); + + virtual void Push( const wxString& aMessage ); + virtual void Revert(); + +private: + PCB_TOOL* m_tool; + virtual EDA_ITEM* parentObject( EDA_ITEM* aItem ) const; +}; + +#endif From 19245070012e9c263bbd15aabc4e80605648564c Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Tue, 10 May 2016 18:09:39 +0200 Subject: [PATCH 14/61] Added a PCB_TOOL subclass. --- pcbnew/moduleframe.cpp | 7 ++- pcbnew/tools/drawing_tool.cpp | 4 +- pcbnew/tools/drawing_tool.h | 4 +- pcbnew/tools/edit_tool.cpp | 2 +- pcbnew/tools/edit_tool.h | 15 +----- pcbnew/tools/pcb_tool.h | 87 +++++++++++++++++++++++++++++++++ pcbnew/tools/selection_tool.cpp | 4 +- pcbnew/tools/selection_tool.h | 4 +- 8 files changed, 101 insertions(+), 26 deletions(-) create mode 100644 pcbnew/tools/pcb_tool.h diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index 20de683891..055fac4049 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -954,13 +954,12 @@ void FOOTPRINT_EDIT_FRAME::setupTools() m_toolManager->RegisterTool( new PLACEMENT_TOOL ); m_toolManager->RegisterTool( new PICKER_TOOL ); - m_toolManager->GetTool()->EditModules( true ); - m_toolManager->GetTool()->EditModules( true ); - m_toolManager->GetTool()->EditModules( true ); + m_toolManager->GetTool()->SetEditModules( true ); + m_toolManager->GetTool()->SetEditModules( true ); + m_toolManager->GetTool()->SetEditModules( true ); m_toolManager->ResetTools( TOOL_BASE::RUN ); m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" ); - } diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index bf08187c2f..b6c60c1661 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -49,8 +49,8 @@ #include DRAWING_TOOL::DRAWING_TOOL() : - TOOL_INTERACTIVE( "pcbnew.InteractiveDrawing" ), m_view( NULL ), - m_controls( NULL ), m_board( NULL ), m_frame( NULL ), m_editModules( false ), m_lineWidth( 1 ) + PCB_TOOL( "pcbnew.InteractiveDrawing" ), m_view( NULL ), + m_controls( NULL ), m_board( NULL ), m_frame( NULL ), m_lineWidth( 1 ) { } diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index 828ac17435..904c18f80b 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -25,7 +25,7 @@ #ifndef __DRAWING_TOOL_H #define __DRAWING_TOOL_H -#include +#include #include namespace KIGFX @@ -43,7 +43,7 @@ class DRAWSEGMENT; * Tool responsible for drawing graphical elements like lines, arcs, circles, etc. */ -class DRAWING_TOOL : public TOOL_INTERACTIVE +class DRAWING_TOOL : public PCB_TOOL { public: DRAWING_TOOL(); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 66e7907456..8d83cdbd1e 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -57,7 +57,7 @@ using namespace std::placeholders; #include EDIT_TOOL::EDIT_TOOL() : - TOOL_INTERACTIVE( "pcbnew.InteractiveEdit" ), m_selectionTool( NULL ), + PCB_TOOL( "pcbnew.InteractiveEdit" ), m_selectionTool( NULL ), m_dragging( false ), m_editModules( false ), m_undoInhibit( 0 ), m_updateFlag( KIGFX::VIEW_ITEM::NONE ) { diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index 8adaf5cb49..ad775b647c 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -27,7 +27,7 @@ #define __EDIT_TOOL_H #include -#include +#include #include class BOARD_ITEM; @@ -45,7 +45,7 @@ class VIEW_GROUP; * using the pcbnew.InteractiveSelection tool. */ -class EDIT_TOOL : public TOOL_INTERACTIVE +class EDIT_TOOL : public PCB_TOOL { public: EDIT_TOOL(); @@ -114,17 +114,6 @@ public: */ int CreateArray( const TOOL_EVENT& aEvent ); - /** - * Function EditModules() - * - * Toggles edit module mode. When enabled, one may select parts of modules individually - * (graphics, pads, etc.), so they can be modified. - * @param aEnabled decides if the mode should be enabled. - */ - void EditModules( bool aEnabled ) - { - m_editModules = aEnabled; - } ///> Sets up handlers for various events. void SetTransitions(); diff --git a/pcbnew/tools/pcb_tool.h b/pcbnew/tools/pcb_tool.h new file mode 100644 index 0000000000..f235945512 --- /dev/null +++ b/pcbnew/tools/pcb_tool.h @@ -0,0 +1,87 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2016 CERN + * @author Tomasz Wlostowski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __PCB_TOOL_H +#define __PCB_TOOL_H + +#include + +#include +#include +#include +#include + +/** + * Class PCB_TOOL + * + * A tool operating on a BOARD object +**/ + +class PCB_TOOL : public TOOL_INTERACTIVE +{ +public: + /** + * Constructor + * + * Creates a tool with given id & name. The name must be unique. */ + PCB_TOOL( TOOL_ID aId, const std::string& aName ) : + TOOL_INTERACTIVE ( aId, aName ), + m_editModules( false ) {}; + + /** + * Constructor + * + * Creates a tool with given name. The name must be unique. */ + PCB_TOOL( const std::string& aName ) : + TOOL_INTERACTIVE ( aName ), + m_editModules( false ) {}; + + virtual ~PCB_TOOL() {}; + + /** + * Function SetEditModules() + * + * Toggles edit module mode. When enabled, one may select parts of modules individually + * (graphics, pads, etc.), so they can be modified. + * @param aEnabled decides if the mode should be enabled. + */ + void SetEditModules( bool aEnabled ) + { + m_editModules = aEnabled; + } + + bool EditingModules() const + { + return m_editModules; + } + +protected: + KIGFX::VIEW* view() const { return getView(); } + PCB_EDIT_FRAME* frame() const { return getEditFrame(); } + BOARD* board() const { return getModel(); } + + bool m_editModules; +}; + +#endif diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 4f81e41612..97c32a5bae 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -68,8 +68,8 @@ public: SELECTION_TOOL::SELECTION_TOOL() : - TOOL_INTERACTIVE( "pcbnew.InteractiveSelection" ), - m_frame( NULL ), m_additive( false ), m_multiple( false ), m_editModules( false ), + PCB_TOOL( "pcbnew.InteractiveSelection" ), + m_frame( NULL ), m_additive( false ), m_multiple( false ), m_locked( true ), m_menu( this ), m_contextMenu( NULL ), m_selectMenu( NULL ), m_zoomMenu( NULL ), m_gridMenu( NULL ) { diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 4a04516f28..b497240c6f 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -27,7 +27,7 @@ #define __SELECTION_TOOL_H #include -#include +#include #include #include @@ -111,7 +111,7 @@ enum SELECTION_LOCK_FLAGS * - takes into account high-contrast & layer visibility settings * - invokes InteractiveEdit tool when user starts to drag selected items */ -class SELECTION_TOOL : public TOOL_INTERACTIVE +class SELECTION_TOOL : public PCB_TOOL { public: SELECTION_TOOL(); From a5b7a7ca0ac44f5f246d6c89a32cd3cc6032f36c Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Wed, 11 May 2016 10:17:34 +0200 Subject: [PATCH 15/61] Changed DuplicateAndAddItem() to parametrized Duplicate(). --- pcbnew/array_creator.cpp | 5 ++--- pcbnew/class_board.cpp | 8 ++++++-- pcbnew/class_board.h | 8 +------- pcbnew/class_module.cpp | 17 ++++++++++++----- pcbnew/class_module.h | 9 +++++---- pcbnew/tools/edit_tool.cpp | 4 ++-- 6 files changed, 28 insertions(+), 23 deletions(-) diff --git a/pcbnew/array_creator.cpp b/pcbnew/array_creator.cpp index 4567579751..6114e0f927 100644 --- a/pcbnew/array_creator.cpp +++ b/pcbnew/array_creator.cpp @@ -81,13 +81,12 @@ void ARRAY_CREATOR::Invoke() { // increment pad numbers if do any renumbering // (we will number again later according to the numbering scheme if set) - new_item = module->DuplicateAndAddItem( - item, array_opts->ShouldNumberItems() ); + new_item = module->Duplicate( item, array_opts->ShouldNumberItems(), true ); } else { // PCB items keep the same numbering - new_item = getBoard()->DuplicateAndAddItem( item ); + new_item = getBoard()->Duplicate( item, true ); // @TODO: we should merge zones. This is a bit tricky, because // the undo command needs saving old area, if it is merged. diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index aac91c9ca9..bfdebdc0d0 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -2770,7 +2770,8 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets, } -BOARD_ITEM* BOARD::DuplicateAndAddItem( const BOARD_ITEM* aItem ) +BOARD_ITEM* BOARD::Duplicate( const BOARD_ITEM* aItem, + bool aAddToBoard ) { BOARD_ITEM* new_item = NULL; @@ -2799,7 +2800,10 @@ BOARD_ITEM* BOARD::DuplicateAndAddItem( const BOARD_ITEM* aItem ) } if( new_item ) - Add( new_item ); + { + if( aAddToBoard ) + Add( new_item ); + } return new_item; } diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index dd4476c267..2d256bb5a1 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -277,13 +277,7 @@ public: ///> @copydoc BOARD_ITEM_CONTAINER::Remove() void Remove( BOARD_ITEM* aBoardItem ) override; - /** - * Function DuplicateAndAddItem - * duplicates an item, and add it to the board list. - * @param aItem The item to duplicate. - * @return BOARD_ITEM* \a the new item which was added. - */ - BOARD_ITEM* DuplicateAndAddItem( const BOARD_ITEM* aItem ); + BOARD_ITEM* Duplicate( const BOARD_ITEM* aItem, bool aAddToBoard = false ); /** * Function GetRatsnest() diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 7ec0d6170d..726cd48cac 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -1110,8 +1110,9 @@ void MODULE::SetOrientation( double newangle ) CalculateBoundingBox(); } -BOARD_ITEM* MODULE::DuplicateAndAddItem( const BOARD_ITEM* aItem, - bool aIncrementPadNumbers ) +BOARD_ITEM* MODULE::Duplicate( const BOARD_ITEM* aItem, + bool aIncrementPadNumbers, + bool aAddToModule ) { BOARD_ITEM* new_item = NULL; D_PAD* new_pad = NULL; @@ -1122,7 +1123,9 @@ BOARD_ITEM* MODULE::DuplicateAndAddItem( const BOARD_ITEM* aItem, { new_pad = new D_PAD( *static_cast( aItem ) ); - Pads().PushBack( new_pad ); + if( aAddToModule ) + Pads().PushBack( new_pad ); + new_item = new_pad; break; } @@ -1137,7 +1140,9 @@ BOARD_ITEM* MODULE::DuplicateAndAddItem( const BOARD_ITEM* aItem, { TEXTE_MODULE* new_text = new TEXTE_MODULE( *old_text ); - GraphicalItems().PushBack( new_text ); + if( aAddToModule ) + GraphicalItems().PushBack( new_text ); + new_item = new_text; } break; @@ -1148,7 +1153,9 @@ BOARD_ITEM* MODULE::DuplicateAndAddItem( const BOARD_ITEM* aItem, EDGE_MODULE* new_edge = new EDGE_MODULE( *static_cast(aItem) ); - GraphicalItems().PushBack( new_edge ); + if( aAddToModule ) + GraphicalItems().PushBack( new_edge ); + new_item = new_edge; break; } diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index 9221d0a22f..715a8f6c85 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -520,12 +520,13 @@ public: void SetPlacementCost90( int aCost ) { m_CntRot90 = aCost; } /** - * Function DuplicateAndAddItem - * Duplicate a given item within the module + * Function Duplicate + * Duplicate a given item within the module, without adding to the board * @return the new item, or NULL if the item could not be duplicated */ - BOARD_ITEM* DuplicateAndAddItem( const BOARD_ITEM* item, - bool aIncrementPadNumbers ); + BOARD_ITEM* Duplicate( const BOARD_ITEM* aItem, + bool aIncrementPadNumbers, + bool aAddToModule = false ); /** * Function Add3DModel diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 8d83cdbd1e..d92e300ad5 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -714,7 +714,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) // TODO move DuplicateAndAddItem() to BOARD_ITEM_CONTAINER? dunno.. if( m_editModules ) - new_item = editFrame->GetBoard()->m_Modules->DuplicateAndAddItem( item, increment ); + new_item = editFrame->GetBoard()->m_Modules->Duplicate( item, increment, true ); else { #if 0 @@ -723,7 +723,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) // so zones are not duplicated if( item->Type() != PCB_ZONE_AREA_T ) #endif - new_item = editFrame->GetBoard()->DuplicateAndAddItem( item ); + new_item = editFrame->GetBoard()->Duplicate( item, true ); } if( new_item ) From b66199342762fe733eef3f481d858eed82601367 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 12 May 2016 13:54:14 +0200 Subject: [PATCH 16/61] Removed SELECTION_TOOL::EditModules() as there is already PCB_TOOL::SetEditModules() and SELECTION_TOOL::m_editModules shadows PCB_TOOL::m_editModules. --- pcbnew/tools/selection_tool.h | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index b497240c6f..508d35f16a 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -137,18 +137,6 @@ public: */ const SELECTION& GetSelection(); - /** - * Function EditModules() - * - * Toggles edit module mode. When enabled, one may select parts of modules individually - * (graphics, pads, etc.), so they can be modified. - * @param aEnabled decides if the mode should be enabled. - */ - inline void EditModules( bool aEnabled ) - { - m_editModules = aEnabled; - } - inline CONDITIONAL_MENU& GetMenu() { return m_menu; @@ -339,9 +327,6 @@ private: /// Flag saying if multiple selection mode is active. bool m_multiple; - /// Edit module mode flag. - bool m_editModules; - /// Can other tools modify locked items. bool m_locked; From dac7c5aa1fd595925a5d789f92e6efb4b804c28a Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 12 May 2016 13:55:58 +0200 Subject: [PATCH 17/61] Store parent object when creating a COMMIT. --- common/commit.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/commit.cpp b/common/commit.cpp index 7f94f90375..c2b14de7f7 100644 --- a/common/commit.cpp +++ b/common/commit.cpp @@ -79,7 +79,7 @@ COMMIT& COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ) if( m_changedItems.find( parent ) != m_changedItems.end() ) return *this; // item already modifed once - makeEntry( aItem, CHT_MODIFY, true ); + makeEntry( parent, CHT_MODIFY, true ); return *this; } @@ -91,7 +91,7 @@ COMMIT& COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ) void COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, CHANGE_TYPE aChangeType ) { - for( int i = 0; i < aItems.GetCount(); i++ ) + for( unsigned int i = 0; i < aItems.GetCount(); i++ ) Stage( aItems.GetPickedItem( i ), aChangeType ); } From 9861b357073e7b8d1bfac45aed17480e40fb7a8b Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 12 May 2016 14:37:07 +0200 Subject: [PATCH 18/61] EDIT_TOOL::hoverSelection() works with current selection. --- pcbnew/tools/edit_tool.cpp | 29 ++++++++++++++++------------- pcbnew/tools/edit_tool.h | 4 ++-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index d92e300ad5..0073886177 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -143,7 +143,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) // Be sure that there is at least one item that we can modify. If nothing was selected before, // try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection) - if( !hoverSelection( selection ) ) + if( !hoverSelection() ) return 0; Activate(); @@ -354,7 +354,7 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) // Shall the selection be cleared at the end? bool unselect = selection.Empty(); - if( !hoverSelection( selection, false ) ) + if( !hoverSelection( false ) ) return 0; // Tracks & vias are treated in a special way: @@ -428,7 +428,7 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) // Shall the selection be cleared at the end? bool unselect = selection.Empty(); - if( !hoverSelection( selection ) || m_selectionTool->CheckLock() == SELECTION_LOCKED ) + if( !hoverSelection() || m_selectionTool->CheckLock() == SELECTION_LOCKED ) return 0; wxPoint rotatePoint = getModificationPoint( selection ); @@ -478,7 +478,7 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent ) // Shall the selection be cleared at the end? bool unselect = selection.Empty(); - if( !hoverSelection( selection ) || m_selectionTool->CheckLock() == SELECTION_LOCKED ) + if( !hoverSelection() || m_selectionTool->CheckLock() == SELECTION_LOCKED ) return 0; wxPoint flipPoint = getModificationPoint( selection ); @@ -523,7 +523,7 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) { const SELECTION& selection = m_selectionTool->GetSelection(); - if( !hoverSelection( selection ) || m_selectionTool->CheckLock() == SELECTION_LOCKED ) + if( !hoverSelection() || m_selectionTool->CheckLock() == SELECTION_LOCKED ) return 0; // Get a copy of the selected items set @@ -616,7 +616,7 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent ) // Shall the selection be cleared at the end? bool unselect = selection.Empty(); - if( !hoverSelection( selection ) || m_selectionTool->CheckLock() == SELECTION_LOCKED ) + if( !hoverSelection() || m_selectionTool->CheckLock() == SELECTION_LOCKED ) return 0; wxPoint translation; @@ -678,7 +678,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) const SELECTION& selection = selTool->GetSelection(); // Be sure that there is at least one item that we can modify - if( !hoverSelection( selection ) ) + if( !hoverSelection() ) return 0; // we have a selection to work on now, so start the tool process @@ -843,7 +843,7 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) const SELECTION& selection = selTool->GetSelection(); // pick up items under the cursor if needed - if( !hoverSelection( selection ) ) + if( !hoverSelection() ) return 0; // we have a selection to work on now, so start the tool process @@ -913,9 +913,11 @@ wxPoint EDIT_TOOL::getModificationPoint( const SELECTION& aSelection ) } -bool EDIT_TOOL::hoverSelection( const SELECTION& aSelection, bool aSanitize ) +bool EDIT_TOOL::hoverSelection( bool aSanitize ) { - if( aSelection.Empty() ) // Try to find an item that could be modified + const SELECTION& selection = m_selectionTool->GetSelection(); + + if( selection.Empty() ) // Try to find an item that could be modified { m_toolMgr->RunAction( COMMON_ACTIONS::selectionCursor, true ); @@ -929,12 +931,13 @@ bool EDIT_TOOL::hoverSelection( const SELECTION& aSelection, bool aSanitize ) if( aSanitize ) m_selectionTool->SanitizeSelection(); - if( aSelection.Empty() ) // TODO is it necessary? + if( selection.Empty() ) // TODO is it necessary? m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); - return !aSelection.Empty(); + return !selection.Empty(); } + void EDIT_TOOL::processUndoBuffer( const PICKED_ITEMS_LIST* aLastChange ) { PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); @@ -1007,7 +1010,7 @@ int EDIT_TOOL::editFootprintInFpEditor( const TOOL_EVENT& aEvent ) const SELECTION& selection = m_selectionTool->GetSelection(); bool unselect = selection.Empty(); - if( !hoverSelection( selection ) ) + if( !hoverSelection() ) return 0; MODULE* mod = uniqueSelected(); diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index ad775b647c..f545387b6d 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -161,8 +161,8 @@ private: wxPoint getModificationPoint( const SELECTION& aSelection ); ///> If there are no items currently selected, it tries to choose the item that is under - ///> the cursor or displays a disambiguation menu if there are multpile items. - bool hoverSelection( const SELECTION& aSelection, bool aSanitize = true ); + ///> the cursor or displays a disambiguation menu if there are multiple items. + bool hoverSelection( bool aSanitize = true ); ///> Processes the current undo buffer since the last change. If the last change does not occur ///> in the current buffer, then the whole list is processed. From 0223425d30317263f31681dc293e14736caef34b Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 9 Jun 2016 14:28:06 +0200 Subject: [PATCH 19/61] COMMIT: changed BOOST_FOREACH to for. --- common/commit.cpp | 14 ++++++++++++-- common/commit.h | 8 -------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/common/commit.cpp b/common/commit.cpp index c2b14de7f7..938f773ed1 100644 --- a/common/commit.cpp +++ b/common/commit.cpp @@ -25,7 +25,6 @@ #include #include -#include COMMIT::COMMIT() { @@ -37,7 +36,7 @@ COMMIT::~COMMIT() { if( !m_committed ) { - BOOST_FOREACH( COMMIT_LINE& ent, m_changes ) + for( COMMIT_LINE& ent : m_changes ) { if( ent.m_copy ) delete ent.m_copy; @@ -89,6 +88,17 @@ COMMIT& COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ) } +COMMIT& COMMIT::Stage( std::vector& container, CHANGE_TYPE aChangeType ) +{ + for( EDA_ITEM* item : container ) + { + Stage( item, aChangeType ); + } + + return *this; +} + + void COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, CHANGE_TYPE aChangeType ) { for( unsigned int i = 0; i < aItems.GetCount(); i++ ) diff --git a/common/commit.h b/common/commit.h index 4256c7f8a2..3e0b11557f 100644 --- a/common/commit.h +++ b/common/commit.h @@ -29,7 +29,6 @@ #include #include -#include class PICKED_ITEMS_LIST; @@ -77,13 +76,6 @@ public: ///> Adds a change of the item aItem of type aChangeType to the change list. virtual COMMIT& Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ); - void Stage( std::vector& container, CHANGE_TYPE aChangeType ) - { - BOOST_FOREACH( EDA_ITEM* item, container ) - { - Stage( item, aChangeType ); - } - } void Stage( const PICKED_ITEMS_LIST& aItems, CHANGE_TYPE aChangeType ); From b8350f037bd44ddf9c269f0a6fac3118234d9a73 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 9 Jun 2016 14:28:54 +0200 Subject: [PATCH 20/61] COMMIT: Added an interface to store items that already have a copy created. --- common/commit.cpp | 108 +++++++++++++++++++++++++++++++++++++--------- common/commit.h | 21 ++++++--- 2 files changed, 102 insertions(+), 27 deletions(-) diff --git a/common/commit.cpp b/common/commit.cpp index 938f773ed1..689d852e10 100644 --- a/common/commit.cpp +++ b/common/commit.cpp @@ -23,8 +23,7 @@ */ #include -#include - +#include COMMIT::COMMIT() { @@ -45,30 +44,17 @@ COMMIT::~COMMIT() } -void COMMIT::makeEntry( EDA_ITEM* aItem, CHANGE_TYPE type, bool saveCopy ) -{ - COMMIT_LINE ent; - - ent.m_item = aItem; - ent.m_type = type; - ent.m_copy = saveCopy ? (EDA_ITEM*) aItem->Clone() : NULL; - - m_changedItems.insert( aItem ); - m_changes.push_back( ent ); -} - - COMMIT& COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ) { switch( aChangeType ) { case CHT_ADD: assert( m_changedItems.find( aItem ) == m_changedItems.end() ); - makeEntry( aItem, CHT_ADD, false ); + makeEntry( aItem, CHT_ADD ); return *this; case CHT_REMOVE: - makeEntry( aItem, CHT_REMOVE, false ); + makeEntry( aItem, CHT_REMOVE ); return *this; case CHT_MODIFY: @@ -78,13 +64,29 @@ COMMIT& COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ) if( m_changedItems.find( parent ) != m_changedItems.end() ) return *this; // item already modifed once - makeEntry( parent, CHT_MODIFY, true ); + makeEntry( parent, CHT_MODIFY, parent->Clone() ); + return *this; } default: assert( false ); } + + return *this; +} + + +COMMIT& COMMIT::Stage( EDA_ITEM* aItem, EDA_ITEM* aCopy ) +{ + EDA_ITEM* parent = parentObject( aItem ); + + if( m_changedItems.find( parent ) != m_changedItems.end() ) + return *this; // item already modifed once + + makeEntry( parent, CHT_MODIFY, aCopy ); + + return *this; } @@ -99,9 +101,75 @@ COMMIT& COMMIT::Stage( std::vector& container, CHANGE_TYPE aChangeTyp } -void COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, CHANGE_TYPE aChangeType ) +COMMIT& COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO_T aModFlag ) { for( unsigned int i = 0; i < aItems.GetCount(); i++ ) - Stage( aItems.GetPickedItem( i ), aChangeType ); + { + UNDO_REDO_T change_type = aItems.GetPickedItemStatus( i ); + EDA_ITEM* item = aItems.GetPickedItem( i ); + EDA_ITEM* copy = NULL; + + if( change_type == UR_UNSPECIFIED ) + change_type = aItems.m_Status; + + if( change_type == UR_UNSPECIFIED ) + change_type = aModFlag; + + if( ( copy = aItems.GetPickedItemLink( i ) ) ) + { + assert( change_type == UR_CHANGED ); + + // There was already a copy created, so use it + Stage( item, copy ); + } + else + { + Stage( item, convert( change_type ) ); + } + } + + return *this; +} + + +void COMMIT::makeEntry( EDA_ITEM* aItem, CHANGE_TYPE aType, EDA_ITEM* aCopy ) +{ + // Expect an item copy if it is going to be modified + assert( !!aCopy == ( aType == CHT_MODIFY ) ); + + COMMIT_LINE ent; + + ent.m_item = aItem; + ent.m_type = aType; + ent.m_copy = aCopy; + + m_changedItems.insert( aItem ); + m_changes.push_back( ent ); +} + + +COMMIT::CHANGE_TYPE COMMIT::convert( UNDO_REDO_T aType ) const +{ + switch( aType ) + { + case UR_NEW: + return CHT_ADD; + + case UR_DELETED: + return CHT_REMOVE; + + default: + assert( false ); + // fall through + + case UR_CHANGED: + case UR_MOVED: + case UR_MIRRORED_X: + case UR_MIRRORED_Y: + case UR_ROTATED: + case UR_ROTATED_CLOCKWISE: + case UR_FLIPPED: + return CHT_MODIFY; + } } diff --git a/common/commit.h b/common/commit.h index 3e0b11557f..9743b3dd03 100644 --- a/common/commit.h +++ b/common/commit.h @@ -27,10 +27,10 @@ #include #include -#include +#include -class PICKED_ITEMS_LIST; +class EDA_ITEM; /** * Class COMMIT @@ -74,10 +74,14 @@ public: } ///> Adds a change of the item aItem of type aChangeType to the change list. - virtual COMMIT& Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ); + COMMIT& Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ); + ///> Adds a change of an item with its copy done before the change has occurred. + COMMIT& Stage( EDA_ITEM* aItem, EDA_ITEM* aCopy ); - void Stage( const PICKED_ITEMS_LIST& aItems, CHANGE_TYPE aChangeType ); + COMMIT& Stage( std::vector& container, CHANGE_TYPE aChangeType ); + + COMMIT& Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO_T aModFlag = UR_UNSPECIFIED ); ///> Executes the changes. virtual void Push( const wxString& aMessage ) = 0; @@ -88,14 +92,17 @@ public: protected: struct COMMIT_LINE { - EDA_ITEM *m_item; - EDA_ITEM *m_copy; + EDA_ITEM* m_item; + EDA_ITEM* m_copy; CHANGE_TYPE m_type; }; - virtual void makeEntry( EDA_ITEM* aItem, CHANGE_TYPE type, bool saveCopy ); + virtual void makeEntry( EDA_ITEM* aItem, CHANGE_TYPE aType, EDA_ITEM* aCopy = NULL ); + virtual EDA_ITEM* parentObject( EDA_ITEM* aItem ) const = 0; + CHANGE_TYPE convert( UNDO_REDO_T aType ) const; + bool m_committed; std::set m_changedItems; From b815ea78653f3af94c4547d017b865c30ddee41e Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 15 Jun 2016 10:06:54 +0200 Subject: [PATCH 21/61] Removed remaining m_editModules flags. --- pcbnew/tools/drawing_tool.h | 14 -------------- pcbnew/tools/edit_tool.cpp | 3 +-- pcbnew/tools/edit_tool.h | 3 --- 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index 904c18f80b..dbf9aa6f4d 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -121,17 +121,6 @@ public: */ int SetAnchor( const TOOL_EVENT& aEvent ); - /** - * Function EditModules() - * Toggles edit module mode. When enabled, one may select parts of modules individually - * (graphics, pads, etc.), so they can be modified. - * @param aEnabled decides if the mode should be enabled. - */ - void EditModules( bool aEnabled ) - { - m_editModules = aEnabled; - } - ///> Sets up handlers for various events. void SetTransitions(); @@ -173,9 +162,6 @@ private: BOARD* m_board; PCB_BASE_EDIT_FRAME* m_frame; - /// Edit module mode flag - bool m_editModules; - /// Stores the current line width for multisegment drawing. unsigned int m_lineWidth; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 0073886177..7f5c4d5e70 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -58,8 +58,7 @@ using namespace std::placeholders; EDIT_TOOL::EDIT_TOOL() : PCB_TOOL( "pcbnew.InteractiveEdit" ), m_selectionTool( NULL ), - m_dragging( false ), m_editModules( false ), m_undoInhibit( 0 ), - m_updateFlag( KIGFX::VIEW_ITEM::NONE ) + m_dragging( false ), m_undoInhibit( 0 ), m_updateFlag( KIGFX::VIEW_ITEM::NONE ) { } diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index f545387b6d..5f04c512a2 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -132,9 +132,6 @@ private: ///> of edit reference point). VECTOR2I m_cursor; - /// Edit module mode flag - bool m_editModules; - /// Counter of undo inhibitions. When zero, undo is not inhibited. int m_undoInhibit; From 940765f4b3ee870e96ee018c19a22b7c9780efc0 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 15 Jun 2016 10:15:10 +0200 Subject: [PATCH 22/61] COMMIT class: removed m_committed flag, added clear() and Empty() methods. --- common/commit.cpp | 10 +++------- common/commit.h | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/common/commit.cpp b/common/commit.cpp index 689d852e10..22c053e43b 100644 --- a/common/commit.cpp +++ b/common/commit.cpp @@ -27,19 +27,15 @@ COMMIT::COMMIT() { - m_committed = false; } COMMIT::~COMMIT() { - if( !m_committed ) + for( COMMIT_LINE& ent : m_changes ) { - for( COMMIT_LINE& ent : m_changes ) - { - if( ent.m_copy ) - delete ent.m_copy; - } + if( ent.m_copy ) + delete ent.m_copy; } } diff --git a/common/commit.h b/common/commit.h index 9743b3dd03..e88e99299e 100644 --- a/common/commit.h +++ b/common/commit.h @@ -89,6 +89,11 @@ public: ///> Revertes the commit by restoring the modifed items state. virtual void Revert() = 0; + bool Empty() const + { + return m_changes.empty(); + } + protected: struct COMMIT_LINE { @@ -97,14 +102,19 @@ protected: CHANGE_TYPE m_type; }; + // Should be called in Push() & Revert() methods + void clear() + { + m_changedItems.clear(); + m_changes.clear(); + } + virtual void makeEntry( EDA_ITEM* aItem, CHANGE_TYPE aType, EDA_ITEM* aCopy = NULL ); virtual EDA_ITEM* parentObject( EDA_ITEM* aItem ) const = 0; CHANGE_TYPE convert( UNDO_REDO_T aType ) const; - bool m_committed; - std::set m_changedItems; std::vector m_changes; }; From b25c407576a0a21ee531c0aaef03a2248b59462c Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 15 Jun 2016 10:15:42 +0200 Subject: [PATCH 23/61] Rebuild the old ratsnest model only if GAL is inactive. --- pcbnew/undo_redo.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pcbnew/undo_redo.cpp b/pcbnew/undo_redo.cpp index 338885908f..dd72f59416 100644 --- a/pcbnew/undo_redo.cpp +++ b/pcbnew/undo_redo.cpp @@ -549,7 +549,6 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool // Rebuild pointers and ratsnest that can be changed. if( reBuild_ratsnest ) { - Compile_Ratsnest( NULL, true ); if( IsGalCanvasActive() ) { @@ -558,7 +557,10 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool else ratsnest->Recalculate(); } - + else + { + Compile_Ratsnest( NULL, true ); + } } } From 497fb31ae0a99a55b44a7ced366e8395a62635a5 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 16 Jun 2016 12:19:07 +0200 Subject: [PATCH 24/61] BOARD_COMMIT can be constructed using a PCB_BASE_FRAME*. --- pcbnew/board_commit.cpp | 44 ++++++++++++++++++++++++----------------- pcbnew/board_commit.h | 6 +++++- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index 0fa58381a5..0a53e1f200 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -30,14 +30,21 @@ #include #include -#include #include #include BOARD_COMMIT::BOARD_COMMIT( PCB_TOOL* aTool ) { - m_tool = aTool; + m_toolMgr = aTool->GetManager(); + m_editModules = aTool->EditingModules(); +} + + +BOARD_COMMIT::BOARD_COMMIT( PCB_BASE_FRAME* aFrame ) +{ + m_toolMgr = aFrame->GetToolManager(); + m_editModules = aFrame->IsType( FRAME_PCB_MODULE_EDITOR ); } @@ -50,29 +57,29 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) { // Objects potentially interested in changes: PICKED_ITEMS_LIST undoList; - TOOL_MANAGER* toolMgr = m_tool->GetManager(); - KIGFX::VIEW* view = toolMgr->GetView(); - BOARD* board = (BOARD*) toolMgr->GetModel(); - PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) toolMgr->GetEditFrame(); + KIGFX::VIEW* view = m_toolMgr->GetView(); + BOARD* board = (BOARD*) m_toolMgr->GetModel(); + PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) m_toolMgr->GetEditFrame(); RN_DATA* ratsnest = board->GetRatsnest(); - bool editModules = m_tool->EditingModules(); + if( Empty() ) + return; - // Module items need to be saved in the undo buffer before modification - if( editModules ) + for( COMMIT_LINE& ent : m_changes ) { - frame->SaveCopyInUndoList( board->m_Modules, UR_CHANGED ); - } + // Module items need to be saved in the undo buffer before modification + if( m_editModules ) + { + frame->SaveCopyInUndoList( static_cast( ent.m_copy ), UR_CHANGED ); + } - BOOST_FOREACH( COMMIT_LINE& ent, m_changes ) - { BOARD_ITEM* boardItem = static_cast( ent.m_item ); switch( ent.m_type ) { case CHT_ADD: { - if( !editModules ) + if( !m_editModules ) { ITEM_PICKER itemWrapper( boardItem, UR_NEW ); undoList.PushItem( itemWrapper ); @@ -90,12 +97,13 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) } view->Add( boardItem ); + //ratsnest->Add( boardItem ); // TODO currently done by BOARD::Add() break; } case CHT_REMOVE: { - if( !editModules ) + if( !m_editModules ) { ITEM_PICKER itemWrapper( boardItem, UR_DELETED ); undoList.PushItem( itemWrapper ); @@ -116,7 +124,7 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) case CHT_MODIFY: { - if( !editModules ) + if( !m_editModules ) { ITEM_PICKER itemWrapper( boardItem, UR_CHANGED ); itemWrapper.SetLink( ent.m_copy ); @@ -140,13 +148,13 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) } } - if( !editModules ) + if( !m_editModules ) frame->SaveCopyInUndoList( undoList, UR_UNSPECIFIED ); frame->OnModify(); ratsnest->Recalculate(); - m_committed = true; + clear(); } diff --git a/pcbnew/board_commit.h b/pcbnew/board_commit.h index 84d87f79ef..7f4d09db15 100644 --- a/pcbnew/board_commit.h +++ b/pcbnew/board_commit.h @@ -30,18 +30,22 @@ class BOARD_ITEM; class PICKED_ITEMS_LIST; class PCB_TOOL; +class PCB_BASE_FRAME; +class TOOL_MANAGER; class BOARD_COMMIT : public COMMIT { public: BOARD_COMMIT( PCB_TOOL* aTool ); + BOARD_COMMIT( PCB_BASE_FRAME* aFrame ); virtual ~BOARD_COMMIT(); virtual void Push( const wxString& aMessage ); virtual void Revert(); private: - PCB_TOOL* m_tool; + TOOL_MANAGER* m_toolMgr; + bool m_editModules; virtual EDA_ITEM* parentObject( EDA_ITEM* aItem ) const; }; From 2ab7196035b37e30f1d99a24687432d99da68238 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 16 Jun 2016 12:19:58 +0200 Subject: [PATCH 25/61] Reenabled and corrected BOARD_COMMIT::Revert(). --- pcbnew/board_commit.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index 0a53e1f200..fec5ff6dc9 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -176,21 +176,19 @@ EDA_ITEM* BOARD_COMMIT::parentObject( EDA_ITEM* aItem ) const void BOARD_COMMIT::Revert() { - #if 0 PICKED_ITEMS_LIST undoList; KIGFX::VIEW* view = m_toolMgr->GetView(); - BOARD *board = (BOARD*) m_toolMgr->GetModel(); - PCB_EDIT_FRAME *frame = (PCB_EDIT_FRAME*) m_toolMgr->GetEditFrame(); + BOARD* board = (BOARD*) m_toolMgr->GetModel(); - - BOOST_FOREACH( COMMIT_LINE& ent, m_changes ) + for( COMMIT_LINE& ent : m_changes ) { - BOARD_ITEM *item = static_cast (ent.m_item); - BOARD_ITEM *copy = static_cast (ent.m_copy); + BOARD_ITEM* item = static_cast( ent.m_item ); + BOARD_ITEM* copy = static_cast( ent.m_copy ); - if(ent.m_type == CHT_MODIFY) + switch( ent.m_type ) + { + case CHT_MODIFY: { - printf("revert %p\n", item ); RN_DATA *ratsnest = board->GetRatsnest(); if( item->Type() == PCB_MODULE_T ) @@ -198,9 +196,9 @@ void BOARD_COMMIT::Revert() MODULE* oldModule = static_cast( item ); oldModule->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) ); } - view->Remove( item ); - ratsnest->Remove( static_cast ( item ) ); + view->Remove( item ); + ratsnest->Remove( static_cast( item ) ); item->SwapData( copy ); // Update all pads/drawings/texts, as they become invalid @@ -210,14 +208,19 @@ void BOARD_COMMIT::Revert() MODULE* newModule = static_cast( item ); newModule->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) ); } + view->Add( item ); ratsnest->Add( item ); - item->ClearFlags( SELECTED ); + break; + } + default: + assert( false ); // not implemented break; } } - #endif + + clear(); } From 992ca6e7c718605ea8bb0891853ecead77acd700 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 16 Jun 2016 12:20:56 +0200 Subject: [PATCH 26/61] Fixed removal function in BOARD_COMMIT. --- pcbnew/board_commit.cpp | 94 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 87 insertions(+), 7 deletions(-) diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index fec5ff6dc9..354835b52d 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -107,18 +107,98 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) { ITEM_PICKER itemWrapper( boardItem, UR_DELETED ); undoList.PushItem( itemWrapper ); - board->Remove( boardItem ); - } else { - board->m_Modules->Remove( boardItem ); } - if(boardItem->Type() == PCB_MODULE_T ) + switch( boardItem->Type() ) { - MODULE* mod = static_cast( boardItem ); - mod->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) ); + case PCB_MODULE_T: + { + // There are no modules inside a module yet + assert( !m_editModules ); + + MODULE* module = static_cast( boardItem ); + module->ClearFlags(); + module->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) ); + + view->Remove( module ); + board->Remove( module ); + + // Clear flags to indicate, that the ratsnest, list of nets & pads are not valid anymore + board->m_Status_Pcb = 0; + } + break; + + // Module items + case PCB_PAD_T: + case PCB_MODULE_EDGE_T: + case PCB_MODULE_TEXT_T: + { + // Do not allow footprint text removal when not editing a module + if( !m_editModules ) + break; + + bool remove = true; + + if( boardItem->Type() == PCB_MODULE_TEXT_T ) + { + TEXTE_MODULE* text = static_cast( boardItem ); + + switch( text->GetType() ) + { + case TEXTE_MODULE::TEXT_is_REFERENCE: + //DisplayError( frame, _( "Cannot delete component reference." ) ); + remove = false; + break; + + case TEXTE_MODULE::TEXT_is_VALUE: + //DisplayError( frame, _( "Cannot delete component value." ) ); + remove = false; + break; + + case TEXTE_MODULE::TEXT_is_DIVERS: // suppress warnings + break; + + default: + assert( false ); + break; + } + } + + if( remove ) + { + view->Remove( boardItem ); + + MODULE* module = static_cast( boardItem->GetParent() ); + module->Remove( boardItem ); + module->SetLastEditTime(); + board->m_Status_Pcb = 0; // it is done in the legacy view + + // Footprint editor saves a full copy of the footprint in the undo buffer, + // so we have to actually delete the text/drawing/pad to avoid memleaks + boardItem->DeleteStructure(); + } + + break; } - view->Remove( boardItem ); + case PCB_LINE_T: // a segment not on copper layers + case PCB_TEXT_T: // a text on a layer + case PCB_TRACE_T: // a track segment (segment on a copper layer) + case PCB_VIA_T: // a via (like track segment on a copper layer) + case PCB_DIMENSION_T: // a dimension (graphic item) + case PCB_TARGET_T: // a target (graphic item) + case PCB_MARKER_T: // a marker used to show something + case PCB_ZONE_T: // SEG_ZONE items are now deprecated + case PCB_ZONE_AREA_T: + view->Remove( boardItem ); + board->Remove( boardItem ); + //ratsnest->Remove( boardItem ); // currently done by BOARD::Remove() + break; + + default: // other types do not need to (or should not) be handled + assert( false ); + break; + } break; } From c7ce82a4bf2bae2afb8210e98305edf95dd994ab Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 20 Jun 2016 11:20:22 +0200 Subject: [PATCH 27/61] BOARD_COMMIT creates only one copy of a modified module --- pcbnew/board_commit.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index 354835b52d..df9d01679b 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -61,6 +61,7 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) BOARD* board = (BOARD*) m_toolMgr->GetModel(); PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) m_toolMgr->GetEditFrame(); RN_DATA* ratsnest = board->GetRatsnest(); + std::set savedModules; if( Empty() ) return; @@ -70,10 +71,29 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) // Module items need to be saved in the undo buffer before modification if( m_editModules ) { - frame->SaveCopyInUndoList( static_cast( ent.m_copy ), UR_CHANGED ); - } + // Be sure that we are storing a module + if( ent.m_item->Type() != PCB_MODULE_T ) + ent.m_item = ent.m_item->GetParent(); - BOARD_ITEM* boardItem = static_cast( ent.m_item ); + // We have not saved the module yet, so let's create an entry + if( savedModules.count( ent.m_item ) == 0 ) + { + if( !ent.m_copy ) + { + assert( ent.m_type != CHT_MODIFY ); // too late to make a copy.. + ent.m_copy = ent.m_item->Clone(); + } + + assert( ent.m_item->Type() == PCB_MODULE_T ); + assert( ent.m_copy->Type() == PCB_MODULE_T ); + + ITEM_PICKER itemWrapper( ent.m_item, UR_CHANGED ); + itemWrapper.SetLink( ent.m_copy ); + undoList.PushItem( itemWrapper ); + frame->SaveCopyInUndoList( undoList, UR_CHANGED ); + savedModules.insert( ent.m_item ); + } + } switch( ent.m_type ) { From f1b37109e3896213e2add684bc32df60506d8448 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 20 Jun 2016 11:21:37 +0200 Subject: [PATCH 28/61] BOARD_COMMIT code cleaning Moved a few conditionals to scopes where they can be executed. Simpler way to create ITEM_PICKERs. --- pcbnew/board_commit.cpp | 79 +++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index df9d01679b..d4d90cb491 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -68,6 +68,8 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) for( COMMIT_LINE& ent : m_changes ) { + BOARD_ITEM* boardItem = static_cast( ent.m_item ); + // Module items need to be saved in the undo buffer before modification if( m_editModules ) { @@ -91,7 +93,9 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) itemWrapper.SetLink( ent.m_copy ); undoList.PushItem( itemWrapper ); frame->SaveCopyInUndoList( undoList, UR_CHANGED ); + savedModules.insert( ent.m_item ); + static_cast( ent.m_item )->SetLastEditTime(); } } @@ -101,23 +105,23 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) { if( !m_editModules ) { - ITEM_PICKER itemWrapper( boardItem, UR_NEW ); - undoList.PushItem( itemWrapper ); + undoList.PushItem( ITEM_PICKER( boardItem, UR_NEW ) ); board->Add( boardItem ); + //ratsnest->Add( boardItem ); // TODO currently done by BOARD::Add() + + if( boardItem->Type() == PCB_MODULE_T ) + { + MODULE* mod = static_cast( boardItem ); + mod->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) ); + } } else { + assert( boardItem->Type() != PCB_MODULE_T ); board->m_Modules->Add( boardItem ); } - if( boardItem->Type() == PCB_MODULE_T ) - { - MODULE* mod = static_cast( boardItem ); - mod->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) ); - } - view->Add( boardItem ); - //ratsnest->Add( boardItem ); // TODO currently done by BOARD::Add() break; } @@ -125,29 +129,11 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) { if( !m_editModules ) { - ITEM_PICKER itemWrapper( boardItem, UR_DELETED ); - undoList.PushItem( itemWrapper ); + undoList.PushItem( ITEM_PICKER( boardItem, UR_DELETED ) ); } switch( boardItem->Type() ) { - case PCB_MODULE_T: - { - // There are no modules inside a module yet - assert( !m_editModules ); - - MODULE* module = static_cast( boardItem ); - module->ClearFlags(); - module->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) ); - - view->Remove( module ); - board->Remove( module ); - - // Clear flags to indicate, that the ratsnest, list of nets & pads are not valid anymore - board->m_Status_Pcb = 0; - } - break; - // Module items case PCB_PAD_T: case PCB_MODULE_EDGE_T: @@ -189,18 +175,16 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) view->Remove( boardItem ); MODULE* module = static_cast( boardItem->GetParent() ); - module->Remove( boardItem ); - module->SetLastEditTime(); - board->m_Status_Pcb = 0; // it is done in the legacy view + assert( module && module->Type() == PCB_MODULE_T ); + module->Delete( boardItem ); - // Footprint editor saves a full copy of the footprint in the undo buffer, - // so we have to actually delete the text/drawing/pad to avoid memleaks - boardItem->DeleteStructure(); + board->m_Status_Pcb = 0; // it is done in the legacy view (ratsnest perhaps?) } break; } + // Board items case PCB_LINE_T: // a segment not on copper layers case PCB_TEXT_T: // a text on a layer case PCB_TRACE_T: // a track segment (segment on a copper layer) @@ -215,6 +199,23 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) //ratsnest->Remove( boardItem ); // currently done by BOARD::Remove() break; + case PCB_MODULE_T: + { + // There are no modules inside a module yet + assert( !m_editModules ); + + MODULE* module = static_cast( boardItem ); + module->ClearFlags(); + module->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) ); + + view->Remove( module ); + board->Remove( module ); + + // Clear flags to indicate, that the ratsnest, list of nets & pads are not valid anymore + board->m_Status_Pcb = 0; + } + break; + default: // other types do not need to (or should not) be handled assert( false ); break; @@ -227,23 +228,18 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) if( !m_editModules ) { ITEM_PICKER itemWrapper( boardItem, UR_CHANGED ); + assert( ent.m_copy ); itemWrapper.SetLink( ent.m_copy ); undoList.PushItem( itemWrapper ); } - if( boardItem->Type() == PCB_MODULE_T ) - { - MODULE* mod = static_cast( boardItem ); - //mod->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) ); - mod->RunOnChildren( boost::bind( &RN_DATA::Update, ratsnest, _1 ) ); - } - boardItem->ViewUpdate( KIGFX::VIEW_ITEM::ALL ); ratsnest->Update( boardItem ); break; } default: + assert( false ); break; } } @@ -323,4 +319,3 @@ void BOARD_COMMIT::Revert() clear(); } - From 08d15a9961910ea027fda693cf051e7aa8924edc Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 20 Jun 2016 11:25:40 +0200 Subject: [PATCH 29/61] BOARD_COMMIT::Revert() marked as not tested --- pcbnew/board_commit.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index d4d90cb491..98c1225b0a 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -272,6 +272,8 @@ EDA_ITEM* BOARD_COMMIT::parentObject( EDA_ITEM* aItem ) const void BOARD_COMMIT::Revert() { + assert( false ); // the code below has not been tested + PICKED_ITEMS_LIST undoList; KIGFX::VIEW* view = m_toolMgr->GetView(); BOARD* board = (BOARD*) m_toolMgr->GetModel(); @@ -308,6 +310,7 @@ void BOARD_COMMIT::Revert() view->Add( item ); ratsnest->Add( item ); item->ClearFlags( SELECTED ); + delete copy; break; } From 38177b70b9b5d183e8b678e2b2f382371e76f6b4 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 20 Jun 2016 15:19:45 +0200 Subject: [PATCH 30/61] Comments for COMMIT class --- common/commit.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/commit.h b/common/commit.h index e88e99299e..a036dda30b 100644 --- a/common/commit.h +++ b/common/commit.h @@ -97,8 +97,13 @@ public: protected: struct COMMIT_LINE { + ///> Main item that is added/deleted/modified EDA_ITEM* m_item; + + ///> Optional copy of the item EDA_ITEM* m_copy; + + ///> Modification type CHANGE_TYPE m_type; }; From c4be379b31fa93496403c50a1a176698ebdbb95d Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 20 Jun 2016 15:46:58 +0200 Subject: [PATCH 31/61] Modified properties dialog to take advantage of BOARD_COMMIT class. --- .../dialog_edit_module_for_BoardEditor.cpp | 12 +- .../dialog_edit_module_for_Modedit.cpp | 7 +- pcbnew/dialogs/dialog_edit_module_text.cpp | 7 +- .../dialog_graphic_item_properties.cpp | 6 +- ...og_graphic_item_properties_for_Modedit.cpp | 13 +- pcbnew/dialogs/dialog_pad_properties.cpp | 215 +++++++++--------- pcbnew/dialogs/dialog_pcb_text_properties.cpp | 14 +- .../dialogs/dialog_track_via_properties.cpp | 5 +- pcbnew/dialogs/dialog_track_via_properties.h | 4 +- pcbnew/dimension.cpp | 7 +- pcbnew/target_edit.cpp | 11 +- 11 files changed, 167 insertions(+), 134 deletions(-) diff --git a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp index 0910078a52..6a1589e20b 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -610,6 +611,9 @@ bool DIALOG_MODULE_BOARD_EDITOR::TransferDataFromWindow() wxPoint modpos; wxString msg; + BOARD_COMMIT commit( m_Parent ); + commit.Modify( m_CurrentModule ); + if( !Validate() || !DIALOG_MODULE_BOARD_EDITOR_BASE::TransferDataFromWindow() || !m_PanelProperties->TransferDataFromWindow() ) { @@ -623,10 +627,6 @@ bool DIALOG_MODULE_BOARD_EDITOR::TransferDataFromWindow() return false; } - if( m_CurrentModule->GetFlags() == 0 ) // this is a simple edition, we - // must create an undo entry - m_Parent->SaveCopyInUndoList( m_CurrentModule, UR_CHANGED ); - if( m_DC ) { m_Parent->GetCanvas()->CrossHairOff( m_DC ); @@ -741,7 +741,9 @@ bool DIALOG_MODULE_BOARD_EDITOR::TransferDataFromWindow() m_CurrentModule->CalculateBoundingBox(); - m_Parent->OnModify(); + // This is a simple edition, we must create an undo entry + if( m_CurrentModule->GetFlags() == 0 ) + commit.Push( _( "Modify module properties" ) ); SetReturnCode( PRM_EDITOR_EDIT_OK ); diff --git a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp index 0d1fe110a8..7d7ccf3d35 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -440,6 +441,7 @@ void DIALOG_MODULE_MODULE_EDITOR::OnCancelClick( wxCommandEvent& event ) void DIALOG_MODULE_MODULE_EDITOR::OnOkClick( wxCommandEvent& event ) { + BOARD_COMMIT commit( m_parent ); wxString msg; // First, test for invalid chars in module name @@ -465,7 +467,8 @@ void DIALOG_MODULE_MODULE_EDITOR::OnOkClick( wxCommandEvent& event ) return; } - m_parent->SaveCopyInUndoList( m_currentModule, UR_CHANGED ); + commit.Modify( m_currentModule ); + m_currentModule->SetLocked( m_AutoPlaceCtrl->GetSelection() == 1 ); switch( m_AttributsCtrl->GetSelection() ) @@ -522,7 +525,7 @@ void DIALOG_MODULE_MODULE_EDITOR::OnOkClick( wxCommandEvent& event ) m_currentModule->CalculateBoundingBox(); - m_parent->OnModify(); + commit.Push( _( "Modify module properties" ) ); EndModal( 1 ); } diff --git a/pcbnew/dialogs/dialog_edit_module_text.cpp b/pcbnew/dialogs/dialog_edit_module_text.cpp index 9d38affffb..df809cbefa 100644 --- a/pcbnew/dialogs/dialog_edit_module_text.cpp +++ b/pcbnew/dialogs/dialog_edit_module_text.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -207,11 +208,13 @@ bool DialogEditModuleText::TransferDataToWindow() bool DialogEditModuleText::TransferDataFromWindow() { + BOARD_COMMIT commit( m_parent ); + if( !Validate() || !DialogEditModuleText_base::TransferDataFromWindow() ) return false; if( m_module ) - m_parent->SaveCopyInUndoList( m_module, UR_CHANGED ); + commit.Modify( m_currentText ); #ifndef USE_WX_OVERLAY if( m_dc ) //Erase old text on screen @@ -325,7 +328,7 @@ bool DialogEditModuleText::TransferDataFromWindow() m_parent->Refresh(); #endif - m_parent->OnModify(); + commit.Push( _( "Modify module text" ) ); if( m_module ) m_module->SetLastEditTime(); diff --git a/pcbnew/dialogs/dialog_graphic_item_properties.cpp b/pcbnew/dialogs/dialog_graphic_item_properties.cpp index d8c2098ae5..7790d36aef 100644 --- a/pcbnew/dialogs/dialog_graphic_item_properties.cpp +++ b/pcbnew/dialogs/dialog_graphic_item_properties.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -227,7 +228,8 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow() if( !DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE::TransferDataFromWindow() ) return false; - m_parent->SaveCopyInUndoList( m_item, UR_CHANGED ); + BOARD_COMMIT commit( m_parent ); + commit.Modify( m_item ); wxString msg; @@ -264,7 +266,7 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow() m_item->SetAngle( m_AngleValue * 10.0 ); } - m_parent->OnModify(); + commit.Push( _( "Modify drawing properties" ) ); if( m_DC ) m_item->Draw( m_parent->GetCanvas(), m_DC, GR_OR ); diff --git a/pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp b/pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp index 27dc569d7b..81c1f99e93 100644 --- a/pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp +++ b/pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -212,6 +213,9 @@ void DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES::OnLayerChoice( wxCommandEvent& even bool DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES::TransferDataFromWindow() { + BOARD_COMMIT commit( m_parent ); + commit.Modify( m_module ); + if( !DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE::TransferDataFromWindow() ) return false; @@ -223,14 +227,10 @@ bool DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES::TransferDataFromWindow() * confirmation is requested */ if( !IsOK( NULL, _( "The graphic item will be on a copper layer. This is very dangerous. Are you sure?" ) ) ) - return false;; + return false; } - m_parent->SaveCopyInUndoList( m_module, UR_CHANGED ); - m_module->SetLastEditTime(); - wxString msg; - wxPoint coord; msg = m_Center_StartXCtrl->GetValue(); @@ -262,7 +262,8 @@ bool DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES::TransferDataFromWindow() m_item->SetAngle( m_AngleValue * 10.0 ); } - m_parent->OnModify(); + commit.Push( _( "Modify module graphic item" ) ); + m_parent->SetMsgPanel( m_item ); return true; diff --git a/pcbnew/dialogs/dialog_pad_properties.cpp b/pcbnew/dialogs/dialog_pad_properties.cpp index 34b88478d5..a56522e261 100644 --- a/pcbnew/dialogs/dialog_pad_properties.cpp +++ b/pcbnew/dialogs/dialog_pad_properties.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -921,6 +922,8 @@ bool DIALOG_PAD_PROPERTIES::TransferDataToWindow() bool DIALOG_PAD_PROPERTIES::TransferDataFromWindow() { + BOARD_COMMIT commit( m_parent ); + if( !wxDialog::TransferDataFromWindow() ) return false; @@ -940,114 +943,116 @@ bool DIALOG_PAD_PROPERTIES::TransferDataFromWindow() // m_padMaster is a pattern: ensure there is no net for this pad: m_padMaster->SetNetCode( NETINFO_LIST::UNCONNECTED ); - if( m_currentPad ) // Set current Pad parameters + if( !m_currentPad ) // Set current Pad parameters + return false; + + commit.Modify( m_currentPad ); + + wxSize size; + MODULE* footprint = m_currentPad->GetParent(); + + footprint->SetLastEditTime(); + + // redraw the area where the pad was, without pad (delete pad on screen) + m_currentPad->SetFlags( DO_NOT_DRAW ); + m_parent->GetCanvas()->RefreshDrawingRect( m_currentPad->GetBoundingBox() ); + m_currentPad->ClearFlags( DO_NOT_DRAW ); + + // Update values + m_currentPad->SetShape( m_padMaster->GetShape() ); + m_currentPad->SetAttribute( m_padMaster->GetAttribute() ); + + if( m_currentPad->GetPosition() != m_padMaster->GetPosition() ) { - wxSize size; - MODULE* footprint = m_currentPad->GetParent(); - - m_parent->SaveCopyInUndoList( footprint, UR_CHANGED ); - footprint->SetLastEditTime(); - - // redraw the area where the pad was, without pad (delete pad on screen) - m_currentPad->SetFlags( DO_NOT_DRAW ); - m_parent->GetCanvas()->RefreshDrawingRect( m_currentPad->GetBoundingBox() ); - m_currentPad->ClearFlags( DO_NOT_DRAW ); - - // Update values - m_currentPad->SetShape( m_padMaster->GetShape() ); - m_currentPad->SetAttribute( m_padMaster->GetAttribute() ); - - if( m_currentPad->GetPosition() != m_padMaster->GetPosition() ) - { - m_currentPad->SetPosition( m_padMaster->GetPosition() ); - rastnestIsChanged = true; - } - - // compute the pos 0 value, i.e. pad position for footprint with orientation = 0 - // i.e. relative to footprint origin (footprint position) - wxPoint pt = m_currentPad->GetPosition() - footprint->GetPosition(); - - RotatePoint( &pt, -footprint->GetOrientation() ); - - m_currentPad->SetPos0( pt ); - - m_currentPad->SetOrientation( m_padMaster->GetOrientation() * isign - + footprint->GetOrientation() ); - - m_currentPad->SetSize( m_padMaster->GetSize() ); - - size = m_padMaster->GetDelta(); - size.y *= isign; - m_currentPad->SetDelta( size ); - - m_currentPad->SetDrillSize( m_padMaster->GetDrillSize() ); - m_currentPad->SetDrillShape( m_padMaster->GetDrillShape() ); - - wxPoint offset = m_padMaster->GetOffset(); - offset.y *= isign; - m_currentPad->SetOffset( offset ); - - m_currentPad->SetPadToDieLength( m_padMaster->GetPadToDieLength() ); - - if( m_currentPad->GetLayerSet() != m_padMaster->GetLayerSet() ) - { - rastnestIsChanged = true; - m_currentPad->SetLayerSet( m_padMaster->GetLayerSet() ); - } - - if( m_isFlipped ) - { - m_currentPad->SetLayerSet( FlipLayerMask( m_currentPad->GetLayerSet() ) ); - } - - m_currentPad->SetPadName( m_padMaster->GetPadName() ); - - wxString padNetname; - - // For PAD_ATTRIB_HOLE_NOT_PLATED, ensure there is no net name selected - if( m_padMaster->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED ) - padNetname = m_PadNetNameCtrl->GetValue(); - - if( m_currentPad->GetNetname() != padNetname ) - { - const NETINFO_ITEM* netinfo = m_board->FindNet( padNetname ); - - if( !padNetname.IsEmpty() && netinfo == NULL ) - { - DisplayError( NULL, _( "Unknown netname, netname not changed" ) ); - } - else if( netinfo ) - { - rastnestIsChanged = true; - m_currentPad->SetNetCode( netinfo->GetNet() ); - } - } - - m_currentPad->SetLocalClearance( m_padMaster->GetLocalClearance() ); - m_currentPad->SetLocalSolderMaskMargin( m_padMaster->GetLocalSolderMaskMargin() ); - m_currentPad->SetLocalSolderPasteMargin( m_padMaster->GetLocalSolderPasteMargin() ); - m_currentPad->SetLocalSolderPasteMarginRatio( m_padMaster->GetLocalSolderPasteMarginRatio() ); - m_currentPad->SetZoneConnection( m_padMaster->GetZoneConnection() ); - m_currentPad->SetThermalWidth( m_padMaster->GetThermalWidth() ); - m_currentPad->SetThermalGap( m_padMaster->GetThermalGap() ); - m_currentPad->SetRoundRectRadiusRatio( m_padMaster->GetRoundRectRadiusRatio() ); - - // rounded rect pads with radius ratio = 0 are in fact rect pads. - // So set the right shape (and perhaps issues with a radius = 0) - if( m_currentPad->GetShape() == PAD_SHAPE_ROUNDRECT && - m_currentPad->GetRoundRectRadiusRatio() == 0.0 ) - { - m_currentPad->SetShape( PAD_SHAPE_RECT ); - } - - footprint->CalculateBoundingBox(); - m_parent->SetMsgPanel( m_currentPad ); - - // redraw the area where the pad was - m_parent->GetCanvas()->RefreshDrawingRect( m_currentPad->GetBoundingBox() ); - m_parent->OnModify(); + m_currentPad->SetPosition( m_padMaster->GetPosition() ); + rastnestIsChanged = true; } + // compute the pos 0 value, i.e. pad position for footprint with orientation = 0 + // i.e. relative to footprint origin (footprint position) + wxPoint pt = m_currentPad->GetPosition() - footprint->GetPosition(); + + RotatePoint( &pt, -footprint->GetOrientation() ); + + m_currentPad->SetPos0( pt ); + + m_currentPad->SetOrientation( m_padMaster->GetOrientation() * isign + + footprint->GetOrientation() ); + + m_currentPad->SetSize( m_padMaster->GetSize() ); + + size = m_padMaster->GetDelta(); + size.y *= isign; + m_currentPad->SetDelta( size ); + + m_currentPad->SetDrillSize( m_padMaster->GetDrillSize() ); + m_currentPad->SetDrillShape( m_padMaster->GetDrillShape() ); + + wxPoint offset = m_padMaster->GetOffset(); + offset.y *= isign; + m_currentPad->SetOffset( offset ); + + m_currentPad->SetPadToDieLength( m_padMaster->GetPadToDieLength() ); + + if( m_currentPad->GetLayerSet() != m_padMaster->GetLayerSet() ) + { + rastnestIsChanged = true; + m_currentPad->SetLayerSet( m_padMaster->GetLayerSet() ); + } + + if( m_isFlipped ) + { + m_currentPad->SetLayerSet( FlipLayerMask( m_currentPad->GetLayerSet() ) ); + } + + m_currentPad->SetPadName( m_padMaster->GetPadName() ); + + wxString padNetname; + + // For PAD_ATTRIB_HOLE_NOT_PLATED, ensure there is no net name selected + if( m_padMaster->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED ) + padNetname = m_PadNetNameCtrl->GetValue(); + + if( m_currentPad->GetNetname() != padNetname ) + { + const NETINFO_ITEM* netinfo = m_board->FindNet( padNetname ); + + if( !padNetname.IsEmpty() && netinfo == NULL ) + { + DisplayError( NULL, _( "Unknown netname, netname not changed" ) ); + } + else if( netinfo ) + { + rastnestIsChanged = true; + m_currentPad->SetNetCode( netinfo->GetNet() ); + } + } + + m_currentPad->SetLocalClearance( m_padMaster->GetLocalClearance() ); + m_currentPad->SetLocalSolderMaskMargin( m_padMaster->GetLocalSolderMaskMargin() ); + m_currentPad->SetLocalSolderPasteMargin( m_padMaster->GetLocalSolderPasteMargin() ); + m_currentPad->SetLocalSolderPasteMarginRatio( m_padMaster->GetLocalSolderPasteMarginRatio() ); + m_currentPad->SetZoneConnection( m_padMaster->GetZoneConnection() ); + m_currentPad->SetThermalWidth( m_padMaster->GetThermalWidth() ); + m_currentPad->SetThermalGap( m_padMaster->GetThermalGap() ); + m_currentPad->SetRoundRectRadiusRatio( m_padMaster->GetRoundRectRadiusRatio() ); + + // rounded rect pads with radius ratio = 0 are in fact rect pads. + // So set the right shape (and perhaps issues with a radius = 0) + if( m_currentPad->GetShape() == PAD_SHAPE_ROUNDRECT && + m_currentPad->GetRoundRectRadiusRatio() == 0.0 ) + { + m_currentPad->SetShape( PAD_SHAPE_RECT ); + } + + footprint->CalculateBoundingBox(); + m_parent->SetMsgPanel( m_currentPad ); + + // redraw the area where the pad was + m_parent->GetCanvas()->RefreshDrawingRect( m_currentPad->GetBoundingBox() ); + + commit.Push( _( "Modify pad" ) ); + if( rastnestIsChanged ) // The net ratsnest must be recalculated m_board->m_Status_Pcb = 0; diff --git a/pcbnew/dialogs/dialog_pcb_text_properties.cpp b/pcbnew/dialogs/dialog_pcb_text_properties.cpp index 0e83ad0f71..32f19d2855 100644 --- a/pcbnew/dialogs/dialog_pcb_text_properties.cpp +++ b/pcbnew/dialogs/dialog_pcb_text_properties.cpp @@ -43,6 +43,7 @@ #include #include #include +#include class PCB_EDIT_FRAME; @@ -188,10 +189,12 @@ bool DIALOG_PCB_TEXT_PROPERTIES::TransferDataToWindow() bool DIALOG_PCB_TEXT_PROPERTIES::TransferDataFromWindow() { - if( !DIALOG_PCB_TEXT_PROPERTIES_BASE::TransferDataFromWindow() ) return false; + BOARD_COMMIT commit( m_Parent ); + commit.Modify( m_SelectedPCBText ); + // Test for acceptable layer. // Incorrect layer can happen for old boards, // having texts on edge cut layer for instance @@ -206,8 +209,7 @@ bool DIALOG_PCB_TEXT_PROPERTIES::TransferDataFromWindow() // If no other command in progress, prepare undo command // (for a command in progress, will be made later, at the completion of command) - if( m_SelectedPCBText->GetFlags() == 0 ) - m_Parent->SaveCopyInUndoList( m_SelectedPCBText, UR_CHANGED ); + bool pushCommit = ( m_SelectedPCBText->GetFlags() == 0 ); /* set flag in edit to force undo/redo/abort proper operation, * and avoid new calls to SaveCopyInUndoList for the same text @@ -303,9 +305,11 @@ bool DIALOG_PCB_TEXT_PROPERTIES::TransferDataFromWindow() m_SelectedPCBText->Draw( m_Parent->GetCanvas(), m_DC, GR_OR ); } #else - m_parent->Refresh(); + m_Parent->Refresh(); #endif - m_Parent->OnModify(); + + if( pushCommit ) + commit.Push( _( "Change text properties" ) ); return true; } diff --git a/pcbnew/dialogs/dialog_track_via_properties.cpp b/pcbnew/dialogs/dialog_track_via_properties.cpp index 8bd3918ec8..78ca781e44 100644 --- a/pcbnew/dialogs/dialog_track_via_properties.cpp +++ b/pcbnew/dialogs/dialog_track_via_properties.cpp @@ -29,6 +29,8 @@ #include #include +#include + DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParent, const SELECTION& aItems ) : DIALOG_TRACK_VIA_PROPERTIES_BASE( aParent ), m_items( aItems ), m_trackStartX( aParent, m_TrackStartXCtrl, m_TrackStartXUnit ), @@ -202,7 +204,7 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen } -bool DIALOG_TRACK_VIA_PROPERTIES::Apply() +bool DIALOG_TRACK_VIA_PROPERTIES::Apply( COMMIT& aCommit ) { if( !check() ) return false; @@ -214,6 +216,7 @@ bool DIALOG_TRACK_VIA_PROPERTIES::Apply() for( int i = 0; i < m_items.Size(); ++i ) { BOARD_ITEM* item = m_items.Item( i ); + aCommit.Modify( item ); switch( item->Type() ) { diff --git a/pcbnew/dialogs/dialog_track_via_properties.h b/pcbnew/dialogs/dialog_track_via_properties.h index 32f739308c..206f08a6c5 100644 --- a/pcbnew/dialogs/dialog_track_via_properties.h +++ b/pcbnew/dialogs/dialog_track_via_properties.h @@ -28,6 +28,8 @@ #include struct SELECTION; +class COMMIT; + class PCB_BASE_FRAME; class DIALOG_TRACK_VIA_PROPERTIES : public DIALOG_TRACK_VIA_PROPERTIES_BASE @@ -36,7 +38,7 @@ public: DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParent, const SELECTION& aItems ); ///> Applies values from the dialog to the selected items. - bool Apply(); + bool Apply( COMMIT& aCommit ); private: void onClose( wxCloseEvent& aEvent ); diff --git a/pcbnew/dimension.cpp b/pcbnew/dimension.cpp index 1cf4e5c23d..28f3c91480 100644 --- a/pcbnew/dimension.cpp +++ b/pcbnew/dimension.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -161,6 +162,8 @@ DIALOG_DIMENSION_EDITOR::DIALOG_DIMENSION_EDITOR( PCB_EDIT_FRAME* aParent, void DIALOG_DIMENSION_EDITOR::OnOKClick( wxCommandEvent& event ) { + BOARD_COMMIT commit( m_parent ); + LAYER_ID newlayer = ToLAYER_ID( m_SelLayerBox->GetLayerSelection() ); if( !m_parent->GetBoard()->IsLayerEnabled( newlayer ) ) @@ -177,7 +180,7 @@ void DIALOG_DIMENSION_EDITOR::OnOKClick( wxCommandEvent& event ) } #endif - m_parent->SaveCopyInUndoList(m_currentDimension, UR_CHANGED); + commit.Modify( m_currentDimension ); if( m_Name->GetValue() != wxEmptyString ) { @@ -228,7 +231,7 @@ void DIALOG_DIMENSION_EDITOR::OnOKClick( wxCommandEvent& event ) m_parent->Refresh(); #endif - m_parent->OnModify(); + commit.Push( _( "Modifed dimensions properties" ) ); event.Skip(); // ends returning wxID_OK (default behavior) } diff --git a/pcbnew/target_edit.cpp b/pcbnew/target_edit.cpp index 77d353db82..4e73ba3500 100644 --- a/pcbnew/target_edit.cpp +++ b/pcbnew/target_edit.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -128,12 +129,14 @@ void TARGET_PROPERTIES_DIALOG_EDITOR::OnCancelClick( wxCommandEvent& event ) */ void TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick( wxCommandEvent& event ) { + BOARD_COMMIT commit( m_Parent ); + commit.Modify( m_Target ); + if( m_DC ) m_Target->Draw( m_Parent->GetCanvas(), m_DC, GR_XOR ); // Save old item in undo list, if is is not currently edited (will be later if so) - if( m_Target->GetFlags() == 0 ) - m_Parent->SaveCopyInUndoList( m_Target, UR_CHANGED ); + bool pushCommit = ( m_Target->GetFlags() == 0 ); if( m_Target->GetFlags() != 0 ) // other edition in progress (MOVE, NEW ..) m_Target->SetFlags( IN_EDIT ); // set flag in edit to force @@ -150,7 +153,9 @@ void TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick( wxCommandEvent& event ) if( m_DC ) m_Target->Draw( m_Parent->GetCanvas(), m_DC, ( m_Target->IsMoving() ) ? GR_XOR : GR_OR ); - m_Parent->OnModify(); + if( pushCommit ) + commit.Push( _( "Modified alignment target" ) ); + EndModal( 1 ); } From acd7214586d7445c15dda1b33a7be3ff3d76c251 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 20 Jun 2016 16:43:07 +0200 Subject: [PATCH 32/61] Moved commit.h to 'include' directory --- {common => include}/commit.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {common => include}/commit.h (100%) diff --git a/common/commit.h b/include/commit.h similarity index 100% rename from common/commit.h rename to include/commit.h From 86b906463f1ab1ce173460a66d597164cb35e974 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 21 Jun 2016 13:46:39 +0200 Subject: [PATCH 33/61] Fixed an assert in 'Create array' dialog --- pcbnew/dialogs/dialog_create_array_base.cpp | 38 ++++++++++----------- pcbnew/dialogs/dialog_create_array_base.fbp | 37 ++++++++++---------- pcbnew/dialogs/dialog_create_array_base.h | 2 +- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/pcbnew/dialogs/dialog_create_array_base.cpp b/pcbnew/dialogs/dialog_create_array_base.cpp index 67d5e6ef9e..0e1e2ceed4 100644 --- a/pcbnew/dialogs/dialog_create_array_base.cpp +++ b/pcbnew/dialogs/dialog_create_array_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Mar 9 2016) +// C++ code generated with wxFormBuilder (version Jun 21 2016) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -290,19 +290,19 @@ DIALOG_CREATE_ARRAY_BASE::DIALOG_CREATE_ARRAY_BASE( wxWindow* parent, wxWindowID // Connect Events this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_CREATE_ARRAY_BASE::OnClose ) ); - m_entryNx->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryNy->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryDx->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryDy->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryOffsetX->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryOffsetY->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryStagger->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryNx->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryNy->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryDx->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryDy->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryOffsetX->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryOffsetY->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryStagger->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_rbGridStartNumberingOpt->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_radioBoxGridNumberingScheme->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryCentreX->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryCentreY->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryCircAngle->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryCircCount->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryCircAngle->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryCircCount->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_rbCircStartNumberingOpt->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_stdButtonsOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnOkClick ), NULL, this ); } @@ -311,19 +311,19 @@ DIALOG_CREATE_ARRAY_BASE::~DIALOG_CREATE_ARRAY_BASE() { // Disconnect Events this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_CREATE_ARRAY_BASE::OnClose ) ); - m_entryNx->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryNy->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryDx->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryDy->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryOffsetX->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryOffsetY->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryStagger->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryNx->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryNy->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryDx->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryDy->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryOffsetX->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryOffsetY->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryStagger->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_rbGridStartNumberingOpt->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_radioBoxGridNumberingScheme->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryCentreX->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryCentreY->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryCircAngle->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_entryCircCount->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryCircAngle->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_entryCircCount->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_rbCircStartNumberingOpt->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_stdButtonsOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnOkClick ), NULL, this ); diff --git a/pcbnew/dialogs/dialog_create_array_base.fbp b/pcbnew/dialogs/dialog_create_array_base.fbp index b4af4d44b9..a9d0660856 100644 --- a/pcbnew/dialogs/dialog_create_array_base.fbp +++ b/pcbnew/dialogs/dialog_create_array_base.fbp @@ -446,8 +446,8 @@ - - OnParameterChanged + OnParameterChanged + @@ -626,8 +626,8 @@ - - OnParameterChanged + OnParameterChanged + @@ -806,8 +806,8 @@ - - OnParameterChanged + OnParameterChanged + @@ -1072,8 +1072,8 @@ - - OnParameterChanged + OnParameterChanged + @@ -1338,8 +1338,8 @@ - - OnParameterChanged + OnParameterChanged + @@ -1604,8 +1604,8 @@ - - OnParameterChanged + OnParameterChanged + @@ -1870,8 +1870,8 @@ - - OnParameterChanged + OnParameterChanged + @@ -3937,8 +3937,8 @@ - - OnParameterChanged + OnParameterChanged + @@ -4203,8 +4203,8 @@ - - OnParameterChanged + OnParameterChanged + @@ -4399,6 +4399,7 @@ m_circPadNumberingSizer wxVERTICAL + 1 protected diff --git a/pcbnew/dialogs/dialog_create_array_base.h b/pcbnew/dialogs/dialog_create_array_base.h index 0e11e36291..9419cef108 100644 --- a/pcbnew/dialogs/dialog_create_array_base.h +++ b/pcbnew/dialogs/dialog_create_array_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Mar 9 2016) +// C++ code generated with wxFormBuilder (version Jun 21 2016) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! From 74d53e517c0f4f355dc3b1a1bf5006c94804ccd5 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 21 Jun 2016 13:47:12 +0200 Subject: [PATCH 34/61] VIEW_GROUP objects redraw itself after a change --- common/view/view_group.cpp | 6 +++++- include/view/view_group.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/common/view/view_group.cpp b/common/view/view_group.cpp index afcd7af04a..94123f1b28 100644 --- a/common/view/view_group.cpp +++ b/common/view/view_group.cpp @@ -55,18 +55,21 @@ VIEW_GROUP::~VIEW_GROUP() void VIEW_GROUP::Add( VIEW_ITEM* aItem ) { m_items.insert( aItem ); + ViewUpdate(); } void VIEW_GROUP::Remove( VIEW_ITEM* aItem ) { m_items.erase( aItem ); + ViewUpdate(); } void VIEW_GROUP::Clear() { m_items.clear(); + ViewUpdate(); } @@ -128,7 +131,8 @@ void VIEW_GROUP::FreeItems() { delete item; } - m_items.clear(); + + Clear(); } diff --git a/include/view/view_group.h b/include/view/view_group.h index 2a1ad62756..056a812f79 100644 --- a/include/view/view_group.h +++ b/include/view/view_group.h @@ -131,6 +131,7 @@ public: inline virtual void SetLayer( int aLayer ) { m_layer = aLayer; + ViewUpdate(); } /** From 39d5cd2aca56f4f22aa2f9edbb800e5140b27332 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 21 Jun 2016 13:47:43 +0200 Subject: [PATCH 35/61] Unified BOARD::Duplicate() --- pcbnew/class_board.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index bfdebdc0d0..4e1898cff1 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -2778,11 +2778,6 @@ BOARD_ITEM* BOARD::Duplicate( const BOARD_ITEM* aItem, switch( aItem->Type() ) { case PCB_MODULE_T: - { - MODULE* new_module = new MODULE( *static_cast( aItem ) ); - new_item = new_module; - break; - } case PCB_TEXT_T: case PCB_LINE_T: case PCB_TRACE_T: @@ -2799,11 +2794,8 @@ BOARD_ITEM* BOARD::Duplicate( const BOARD_ITEM* aItem, break; } - if( new_item ) - { - if( aAddToBoard ) - Add( new_item ); - } + if( new_item && aAddToBoard ) + Add( new_item ); return new_item; } From 32c4bec31cb07b1e305c03bebdce2f0bd7870020 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 21 Jun 2016 16:54:14 +0200 Subject: [PATCH 36/61] Implemented BOARD_COMMIT::Revert() --- pcbnew/board_commit.cpp | 43 ++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index 98c1225b0a..d379a93708 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -272,11 +272,10 @@ EDA_ITEM* BOARD_COMMIT::parentObject( EDA_ITEM* aItem ) const void BOARD_COMMIT::Revert() { - assert( false ); // the code below has not been tested - PICKED_ITEMS_LIST undoList; KIGFX::VIEW* view = m_toolMgr->GetView(); BOARD* board = (BOARD*) m_toolMgr->GetModel(); + RN_DATA* ratsnest = board->GetRatsnest(); for( COMMIT_LINE& ent : m_changes ) { @@ -285,10 +284,7 @@ void BOARD_COMMIT::Revert() switch( ent.m_type ) { - case CHT_MODIFY: - { - RN_DATA *ratsnest = board->GetRatsnest(); - + case CHT_ADD: if( item->Type() == PCB_MODULE_T ) { MODULE* oldModule = static_cast( item ); @@ -296,29 +292,58 @@ void BOARD_COMMIT::Revert() } view->Remove( item ); - ratsnest->Remove( static_cast( item ) ); + ratsnest->Remove( item ); + break; + + case CHT_REMOVE: + if( item->Type() == PCB_MODULE_T ) + { + MODULE* newModule = static_cast( item ); + newModule->RunOnChildren( boost::bind( &EDA_ITEM::ClearFlags, _1, SELECTED ) ); + newModule->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) ); + } + + view->Add( item ); + ratsnest->Add( item ); + break; + + case CHT_MODIFY: + { + if( item->Type() == PCB_MODULE_T ) + { + MODULE* oldModule = static_cast( item ); + oldModule->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) ); + } + + view->Remove( item ); + ratsnest->Remove( item ); + item->SwapData( copy ); + item->ClearFlags( SELECTED ); + // Update all pads/drawings/texts, as they become invalid // for the VIEW after SwapData() called for modules if( item->Type() == PCB_MODULE_T ) { MODULE* newModule = static_cast( item ); + newModule->RunOnChildren( boost::bind( &EDA_ITEM::ClearFlags, _1, SELECTED ) ); newModule->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) ); } view->Add( item ); ratsnest->Add( item ); - item->ClearFlags( SELECTED ); delete copy; break; } default: - assert( false ); // not implemented + assert( false ); break; } } + ratsnest->Recalculate(); + clear(); } From 5c0605f6dc3067a6af09a400d877d29599b28186 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 16 Aug 2016 10:03:52 +0200 Subject: [PATCH 37/61] Mute a few warnings --- pcbnew/class_board.h | 1 + pcbnew/router/router_tool.cpp | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index 2d256bb5a1..09caae0458 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -224,6 +224,7 @@ private: BOARD& operator=( const BOARD& aOther ) { assert( false ); + return *this; // just to mute warning } public: diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 2e62349371..371d16bcbe 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -829,8 +829,6 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) ctls->SetAutoPan( true ); frame->UndoRedoBlock( true ); - bool modified = false; - while( OPT_TOOL_EVENT evt = Wait() ) { p0 = ctls->GetCursorPosition(); @@ -845,7 +843,7 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) } else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) { - modified = m_router->FixRoute( p0, NULL ); + m_router->FixRoute( p0, NULL ); break; } } From 5a1f52bf30c05b4583e36b213456e268b3060b19 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 21 Jun 2016 17:06:28 +0200 Subject: [PATCH 38/61] Modified tools to use BOARD_COMMIT. --- pcbnew/array_creator.cpp | 100 ++++---- pcbnew/router/length_tuner_tool.cpp | 2 - pcbnew/router/pns_kicad_iface.cpp | 31 +-- pcbnew/router/pns_kicad_iface.h | 2 + pcbnew/router/pns_router.cpp | 4 +- pcbnew/router/pns_router.h | 6 +- pcbnew/router/pns_tool_base.cpp | 1 - pcbnew/router/pns_tool_base.h | 4 +- pcbnew/router/router_preview_item.cpp | 2 - pcbnew/router/router_tool.cpp | 9 - pcbnew/tools/drawing_tool.cpp | 135 +++++----- pcbnew/tools/edit_tool.cpp | 339 +++++-------------------- pcbnew/tools/edit_tool.h | 6 +- pcbnew/tools/module_tools.cpp | 30 +-- pcbnew/tools/pcb_editor_control.cpp | 31 +-- pcbnew/tools/pcbnew_control.cpp | 29 +-- pcbnew/tools/placement_tool.cpp | 341 ++++++++++++-------------- pcbnew/tools/point_editor.cpp | 55 +++-- pcbnew/zones_by_polygon.cpp | 12 +- 19 files changed, 415 insertions(+), 724 deletions(-) diff --git a/pcbnew/array_creator.cpp b/pcbnew/array_creator.cpp index 6114e0f927..5787e35dee 100644 --- a/pcbnew/array_creator.cpp +++ b/pcbnew/array_creator.cpp @@ -28,7 +28,7 @@ #include "array_creator.h" -#include +#include #include @@ -41,6 +41,7 @@ void ARRAY_CREATOR::Invoke() if( numItems == 0 ) return; + BOARD_COMMIT commit( &m_parent ); MODULE* const module = getModule(); const bool isModuleEditor = module != NULL; @@ -52,76 +53,63 @@ void ARRAY_CREATOR::Invoke() DIALOG_CREATE_ARRAY::ARRAY_OPTIONS* const array_opts = dialog.GetArrayOptions(); - if( ret == wxID_OK && array_opts != NULL ) + if( ret != wxID_OK || array_opts == NULL ) + return; + + for ( int i = 0; i < numItems; ++i ) { - PICKED_ITEMS_LIST newItemsList; + BOARD_ITEM* item = getNthItemToArray( i ); - if( isModuleEditor ) + if( item->Type() == PCB_PAD_T && !isModuleEditor ) { - // modedit saves everything upfront - m_parent.SaveCopyInUndoList( getBoard()->m_Modules, UR_CHANGED ); + // If it is not the module editor, then duplicate the parent module instead + item = static_cast( item )->GetParent(); } - for ( int i = 0; i < numItems; ++i ) + // The first item in list is the original item. We do not modify it + for( int ptN = 1; ptN < array_opts->GetArraySize(); ptN++ ) { - BOARD_ITEM* item = getNthItemToArray( i ); + BOARD_ITEM* new_item; - if( item->Type() == PCB_PAD_T && !isModuleEditor ) + if( isModuleEditor ) { - // If it is not the module editor, then duplicate the parent module instead - item = static_cast( item )->GetParent(); + // increment pad numbers if do any renumbering + // (we will number again later according to the numbering scheme if set) + new_item = module->Duplicate( item, array_opts->ShouldNumberItems() ); + } + else + { + // PCB items keep the same numbering + new_item = getBoard()->Duplicate( item ); + + // @TODO: we should merge zones. This is a bit tricky, because + // the undo command needs saving old area, if it is merged. } - // The first item in list is the original item. We do not modify it - for( int ptN = 1; ptN < array_opts->GetArraySize(); ptN++ ) + if( new_item ) { - BOARD_ITEM* new_item; + array_opts->TransformItem( ptN, new_item, rotPoint ); + prePushAction( new_item ); + commit.Add( new_item ); + postPushAction( new_item ); + } - if( isModuleEditor ) + // attempt to renumber items if the array parameters define + // a complete numbering scheme to number by (as opposed to + // implicit numbering by incrementing the items during creation + if( new_item && array_opts->NumberingStartIsSpecified() ) + { + // Renumber pads. Only new pad number renumbering has meaning, + // in the footprint editor. + if( new_item->Type() == PCB_PAD_T ) { - // increment pad numbers if do any renumbering - // (we will number again later according to the numbering scheme if set) - new_item = module->Duplicate( item, array_opts->ShouldNumberItems(), true ); - } - else - { - // PCB items keep the same numbering - new_item = getBoard()->Duplicate( item, true ); - - // @TODO: we should merge zones. This is a bit tricky, because - // the undo command needs saving old area, if it is merged. - } - - if( new_item ) - { - array_opts->TransformItem( ptN, new_item, rotPoint ); - prePushAction( new_item ); - newItemsList.PushItem( new_item ); // For undo list - postPushAction( new_item ); - } - - // attempt to renumber items if the array parameters define - // a complete numbering scheme to number by (as opposed to - // implicit numbering by incrementing the items during creation - if( new_item && array_opts->NumberingStartIsSpecified() ) - { - // Renumber pads. Only new pad number renumbering has meaning, - // in the footprint editor. - if( new_item->Type() == PCB_PAD_T ) - { - const wxString padName = array_opts->GetItemNumber( ptN ); - static_cast( new_item )->SetPadName( padName ); - } + const wxString padName = array_opts->GetItemNumber( ptN ); + static_cast( new_item )->SetPadName( padName ); } } } - - if( !isModuleEditor ) - { - // Add all items as a single undo point for PCB editors - m_parent.SaveCopyInUndoList( newItemsList, UR_NEW ); - } - - finalise(); } + + commit.Push( _( "Create an array" ) ); + finalise(); } diff --git a/pcbnew/router/length_tuner_tool.cpp b/pcbnew/router/length_tuner_tool.cpp index e7cc8064a2..29f49ecfbf 100644 --- a/pcbnew/router/length_tuner_tool.cpp +++ b/pcbnew/router/length_tuner_tool.cpp @@ -229,8 +229,6 @@ void LENGTH_TUNER_TOOL::performTuning() } m_router->StopRouting(); - m_frame->OnModify(); - highlightNet( false ); } diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 2069539da7..79f3ae68d9 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -154,7 +155,7 @@ int PNS_PCBNEW_RULE_RESOLVER::Clearance( const PNS::ITEM* aA, const PNS::ITEM* a int net_b = aB->Net(); int cl_b = ( net_b >= 0 ? m_clearanceCache[net_b].clearance : m_defaultClearance ); - bool linesOnly = aA->OfKind( PNS::ITEM::SEGMENT_T | PNS::ITEM::LINE_T ) + bool linesOnly = aA->OfKind( PNS::ITEM::SEGMENT_T | PNS::ITEM::LINE_T ) && aB->OfKind( PNS::ITEM::SEGMENT_T | PNS::ITEM::LINE_T ); if( linesOnly && net_a >= 0 && net_b >= 0 && m_clearanceCache[net_a].coupledNet == net_b ) @@ -413,11 +414,13 @@ PNS_KICAD_IFACE::PNS_KICAD_IFACE() m_world = nullptr; m_router = nullptr; m_debugDecorator = nullptr; + m_commit = nullptr; } PNS_KICAD_IFACE::~PNS_KICAD_IFACE() { + delete m_commit; delete m_ruleResolver; delete m_debugDecorator; @@ -743,7 +746,7 @@ void PNS_KICAD_IFACE::SyncWorld( PNS::NODE *aWorld ) if( type == PCB_TRACE_T ) { std::unique_ptr< PNS::SEGMENT > segment = syncTrack( t ); if( segment ) { - aWorld->Add( std::move( segment ) ); + aWorld->Add( std::move( segment ) ); } } else if( type == PCB_VIA_T ) { std::unique_ptr< PNS::VIA > via = syncVia( static_cast( t ) ); @@ -821,9 +824,8 @@ void PNS_KICAD_IFACE::RemoveItem( PNS::ITEM* aItem ) if( parent ) { - m_view->Remove( parent ); - m_board->Remove( parent ); - m_undoBuffer.PushItem( ITEM_PICKER( parent, UR_DELETED ) ); + assert( m_commit ); + m_commit->Remove( parent ); } } @@ -871,20 +873,16 @@ void PNS_KICAD_IFACE::AddItem( PNS::ITEM* aItem ) { aItem->SetParent( newBI ); newBI->ClearFlags(); - m_view->Add( newBI ); - m_board->Add( newBI ); - m_undoBuffer.PushItem( ITEM_PICKER( newBI, UR_NEW ) ); - newBI->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); + + assert( m_commit ); + m_commit->Add( newBI ); } } void PNS_KICAD_IFACE::Commit() { - m_board->GetRatsnest()->Recalculate(); - m_frame->SaveCopyInUndoList( m_undoBuffer, UR_UNSPECIFIED ); - m_undoBuffer.ClearItemsList(); - m_frame->OnModify(); + m_commit->Push( wxT( "Added a track" ) ); } @@ -909,6 +907,7 @@ void PNS_KICAD_IFACE::SetView( KIGFX::VIEW *aView ) m_debugDecorator->SetView( m_view ); } + void PNS_KICAD_IFACE::UpdateNet( int aNetCode ) { wxLogTrace( "PNS", "Update-net %d", aNetCode ); @@ -924,7 +923,11 @@ void PNS_KICAD_IFACE::SetRouter( PNS::ROUTER* aRouter ) m_router = aRouter; } -void PNS_KICAD_IFACE::SetHostFrame( PCB_EDIT_FRAME *aFrame ) + +void PNS_KICAD_IFACE::SetHostFrame( PCB_EDIT_FRAME* aFrame ) { m_frame = aFrame; + + delete m_commit; + m_commit = new BOARD_COMMIT( aFrame ); } diff --git a/pcbnew/router/pns_kicad_iface.h b/pcbnew/router/pns_kicad_iface.h index 3cf6ffb2a8..b59228b296 100644 --- a/pcbnew/router/pns_kicad_iface.h +++ b/pcbnew/router/pns_kicad_iface.h @@ -30,6 +30,7 @@ class PNS_PCBNEW_RULE_RESOLVER; class PNS_PCBNEW_DEBUG_DECORATOR; class BOARD; +class BOARD_COMMIT; namespace KIGFX { class VIEW; @@ -75,6 +76,7 @@ private: BOARD* m_board; PICKED_ITEMS_LIST m_undoBuffer; PCB_EDIT_FRAME* m_frame; + BOARD_COMMIT* m_commit; }; #endif diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index 1a72718942..da30f9ac96 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -277,8 +277,8 @@ void ROUTER::updateView( NODE* aNode, ITEM_SET& aCurrent ) for ( auto item : added ) m_iface->DisplayItem( item ); - for ( auto item : removed ) - m_iface->HideItem ( item ); + for( auto item : removed ) + m_iface->HideItem( item ); } diff --git a/pcbnew/router/pns_router.h b/pcbnew/router/pns_router.h index 66b0e529a4..3f732bc9e7 100644 --- a/pcbnew/router/pns_router.h +++ b/pcbnew/router/pns_router.h @@ -144,7 +144,7 @@ public: void SwitchLayer( int layer ); void ToggleViaPlacement(); - void SetOrthoMode ( bool aEnable ); + void SetOrthoMode( bool aEnable ); int GetCurrentLayer() const; const std::vector GetCurrentNets() const; @@ -211,8 +211,7 @@ public: ITEM* QueryItemByParent( const BOARD_ITEM* aItem ) const; - - void SetFailureReason ( const wxString& aReason ) { m_failureReason = aReason; } + void SetFailureReason( const wxString& aReason ) { m_failureReason = aReason; } const wxString& FailureReason() const { return m_failureReason; } PLACEMENT_ALGO* Placer() { return m_placer.get(); } @@ -270,7 +269,6 @@ private: bool m_violation; ROUTING_SETTINGS m_settings; - ///> Stores list of modified items in the current operation SIZES_SETTINGS m_sizes; ROUTER_MODE m_mode; diff --git a/pcbnew/router/pns_tool_base.cpp b/pcbnew/router/pns_tool_base.cpp index 0e99918a35..f65649f5e5 100644 --- a/pcbnew/router/pns_tool_base.cpp +++ b/pcbnew/router/pns_tool_base.cpp @@ -105,7 +105,6 @@ void TOOL_BASE::Reset( RESET_REASON aReason ) m_board = getModel(); m_iface = new PNS_KICAD_IFACE; - m_iface->SetBoard( m_board ); m_iface->SetView( getView() ); m_iface->SetHostFrame( m_frame ); diff --git a/pcbnew/router/pns_tool_base.h b/pcbnew/router/pns_tool_base.h index ceae7b32b1..fea4c0fb4f 100644 --- a/pcbnew/router/pns_tool_base.h +++ b/pcbnew/router/pns_tool_base.h @@ -23,10 +23,12 @@ #ifndef __PNS_TOOL_BASE_H #define __PNS_TOOL_BASE_H +#include #include #include -#include +#include +#include #include diff --git a/pcbnew/router/router_preview_item.cpp b/pcbnew/router/router_preview_item.cpp index 7e15edac01..239985ef6b 100644 --- a/pcbnew/router/router_preview_item.cpp +++ b/pcbnew/router/router_preview_item.cpp @@ -120,7 +120,6 @@ void ROUTER_PREVIEW_ITEM::Update( const PNS::ITEM* aItem ) m_color = COLOR4D( 0, 1, 0, 1 ); ViewSetVisible( true ); - ViewUpdate( GEOMETRY | APPEARANCE ); } @@ -276,7 +275,6 @@ void ROUTER_PREVIEW_ITEM::Line( const SHAPE_LINE_CHAIN& aLine, int aWidth, int a m_shape = aLine.Clone(); ViewSetVisible( true ); - ViewUpdate( GEOMETRY | APPEARANCE ); } diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 371d16bcbe..c7b6efa7d6 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -534,8 +534,6 @@ bool ROUTER_TOOL::finishInteractive() { m_router->StopRouting(); - m_frame->OnModify(); - m_ctls->SetAutoPan( false ); m_ctls->ForceCursorPosition( false ); highlightNet( false ); @@ -740,7 +738,6 @@ int ROUTER_TOOL::mainLoop( PNS::ROUTER_MODE aMode ) void ROUTER_TOOL::performDragging() { - PCB_EDIT_FRAME* frame = getEditFrame(); VIEW_CONTROLS* ctls = getViewControls(); if( m_startItem && m_startItem->IsLocked() ) @@ -787,9 +784,6 @@ void ROUTER_TOOL::performDragging() if( m_router->RoutingInProgress() ) m_router->StopRouting(); - if( modified ) - frame->OnModify(); - m_startItem = NULL; ctls->SetAutoPan( false ); @@ -851,9 +845,6 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) if( m_router->RoutingInProgress() ) m_router->StopRouting(); - if( modified ) - frame->OnModify(); - ctls->SetAutoPan( false ); ctls->ShowCursor( false ); frame->UndoRedoBlock( false ); diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index b6c60c1661..8215c0f60b 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -75,6 +76,7 @@ int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent ) BOARD_ITEM_CONTAINER* parent = m_frame->GetModel(); DRAWSEGMENT* line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; boost::optional startingPoint; + BOARD_COMMIT commit( m_frame ); m_frame->SetToolID( m_editModules ? ID_MODEDIT_LINE_TOOL : ID_PCB_ADD_LINE_BUTT, wxCURSOR_PENCIL, _( "Add graphic line" ) ); @@ -83,10 +85,8 @@ int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent ) { if( line ) { - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( line, UR_NEW ); - - parent->Add( line ); + commit.Add( line ); + commit.Push( _( "Draw a line segment" ) ); startingPoint = line->GetEnd(); } else @@ -107,6 +107,7 @@ int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent ) { BOARD_ITEM_CONTAINER* parent = m_frame->GetModel(); DRAWSEGMENT* circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; + BOARD_COMMIT commit( m_frame ); m_frame->SetToolID( m_editModules ? ID_MODEDIT_CIRCLE_TOOL : ID_PCB_CIRCLE_BUTT, wxCURSOR_PENCIL, _( "Add graphic circle" ) ); @@ -115,10 +116,8 @@ int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent ) { if( circle ) { - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( circle, UR_NEW ); - - m_frame->GetModel()->Add( circle ); + commit.Add( circle ); + commit.Push( _( "Draw a circle" ) ); } circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; @@ -134,6 +133,7 @@ int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent ) { BOARD_ITEM_CONTAINER* parent = m_frame->GetModel(); DRAWSEGMENT* arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; + BOARD_COMMIT commit( m_frame ); m_frame->SetToolID( m_editModules ? ID_MODEDIT_ARC_TOOL : ID_PCB_ARC_BUTT, wxCURSOR_PENCIL, _( "Add graphic arc" ) ); @@ -142,10 +142,8 @@ int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent ) { if( arc ) { - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( arc, UR_NEW ); - - m_frame->GetModel()->Add( arc ); + commit.Add( arc ); + commit.Push( _( "Draw an arc" ) ); } arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; @@ -161,6 +159,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) { BOARD_ITEM* text = NULL; const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings(); + BOARD_COMMIT commit( m_frame ); // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( m_view ); @@ -185,11 +184,10 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) if( text ) { // Delete the old text and have another try - m_frame->GetModel()->Delete( text ); // it was already added by CreateTextPcb() + delete text; text = NULL; preview.Clear(); - preview.ViewUpdate(); m_controls->SetAutoPan( false ); m_controls->CaptureCursor( false ); @@ -225,6 +223,8 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) if( m_editModules ) { TEXTE_MODULE* textMod = new TEXTE_MODULE( (MODULE*) m_frame->GetModel() ); + + textMod->SetLayer( m_frame->GetActiveLayer() ); textMod->SetSize( dsnSettings.m_ModuleTextSize ); textMod->SetThickness( dsnSettings.m_ModuleTextWidth ); textMod->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); @@ -232,15 +232,34 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) DialogEditModuleText textDialog( m_frame, textMod, NULL ); bool placing = textDialog.ShowModal() && ( textMod->GetText().Length() > 0 ); - if( placing ) + if( !placing ) text = textMod; else delete textMod; } else { - assert( !m_editModules ); - text = static_cast( m_frame )->CreateTextePcb( NULL ); + TEXTE_PCB* textPcb = new TEXTE_PCB( m_frame->GetModel() ); + // TODO we have to set IS_NEW, otherwise InstallTextPCB.. creates an undo entry :| LEGACY_CLEANUP + textPcb->SetFlags( IS_NEW ); + + LAYER_ID layer = m_frame->GetActiveLayer(); + textPcb->SetLayer( layer ); + + // Set the mirrored option for layers on the BACK side of the board + if( IsBackLayer( layer ) ) + textPcb->SetMirrored( true ); + + textPcb->SetSize( dsnSettings.m_PcbTextSize ); + textPcb->SetThickness( dsnSettings.m_PcbTextWidth ); + textPcb->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); + + getEditFrame()->InstallTextPCBOptionsFrame( textPcb, NULL ); + + if( textPcb->GetText().IsEmpty() ) + delete textPcb; + else + text = textPcb; } if( text == NULL ) @@ -258,21 +277,11 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) //assert( text->GetSize().x > 0 && text->GetSize().y > 0 ); text->ClearFlags(); - m_view->Add( text ); - - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( text, UR_NEW ); - - if( m_editModules ) - { - m_frame->GetModel()->Add( text ); - } - else - { - // m_board->Add( text ); // it is already added by CreateTextePcb() - } - preview.Remove( text ); + + commit.Add( text ); + commit.Push( _( "Place a text" ) ); + m_controls->CaptureCursor( false ); m_controls->SetAutoPan( false ); m_controls->ShowCursor( true ); @@ -306,6 +315,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) { DIMENSION* dimension = NULL; + BOARD_COMMIT commit( m_frame ); int maxThickness; // Add a VIEW_GROUP that serves as a preview for the new item @@ -338,7 +348,6 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) if( step != SET_ORIGIN ) // start from the beginning { preview.Clear(); - preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); delete dimension; step = SET_ORIGIN; @@ -422,13 +431,11 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) assert( dimension->GetOrigin() != dimension->GetEnd() ); assert( dimension->GetWidth() > 0 ); - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( dimension, UR_NEW ); - - m_view->Add( dimension ); - m_board->Add( dimension ); - preview.Remove( dimension ); + + commit.Add( dimension ); + commit.Push( _( "Draw a dimension" ) ); + } } break; @@ -517,6 +524,7 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( m_view ); + BOARD_COMMIT commit( m_frame ); // Build the undo list & add items to the current view for( auto it = list.begin(), itEnd = list.end(); it != itEnd; ++it ) @@ -554,6 +562,7 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) else if( evt->Category() == TC_COMMAND ) { + // TODO it should be handled by EDIT_TOOL, so add items and select? if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { for( KIGFX::VIEW_GROUP::const_iter it = preview.Begin(), end = preview.End(); it != end; ++it ) @@ -616,20 +625,10 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) item = converted; } - ITEM_PICKER itemWrapper( item, UR_NEW ); - picklist.PushItem( itemWrapper ); - } - - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( picklist, UR_NEW ); - - for( KIGFX::VIEW_GROUP::const_iter it = preview.Begin(); it != preview.End(); ++it ) - { - BOARD_ITEM* item = static_cast( *it ); - parent->Add( item ); - m_view->Add( item ); + commit.Add( item ); } + commit.Push( _( "Place a DXF drawing" ) ); break; } } @@ -664,15 +663,15 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) if( evt->IsClick( BUT_LEFT ) ) { MODULE* module = (MODULE*) m_frame->GetModel(); - - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( module, UR_CHANGED ); + BOARD_COMMIT commit( m_frame ); + commit.Modify( module ); // set the new relative internal local coordinates of footprint items VECTOR2I cursorPos = m_controls->GetCursorPosition(); wxPoint moveVector = module->GetPosition() - wxPoint( cursorPos.x, cursorPos.y ); module->MoveAnchorPosition( moveVector ); - module->ViewUpdate(); + + commit.Push( _( "Move the footprint reference anchor" ) ); // Usually, we do not need to change twice the anchor position, // so deselect the active tool @@ -818,24 +817,14 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, *static_cast( l ) = line45; l->SetEnd( aGraphic->GetStart() ); - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( l, UR_NEW ); - - parent->Add( l ); - m_view->Add( l ); + BOARD_COMMIT commit( m_frame ); + commit.Add( l ); + commit.Push( _( "Draw a line" ) ); } delete aGraphic; aGraphic = NULL; } - else - { - assert( aGraphic->GetLength() > 0 ); - assert( aGraphic->GetWidth() > 0 ); - - m_view->Add( aGraphic ); - aGraphic->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - } preview.Clear(); break; @@ -922,7 +911,6 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic ) if( evt->IsCancel() || evt->IsActivate() ) { preview.Clear(); - preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); delete aGraphic; aGraphic = NULL; break; @@ -1071,6 +1059,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout ) ZONE_CONTAINER* zone = NULL; DRAWSEGMENT line45; DRAWSEGMENT* helperLine = NULL; // we will need more than one helper line + BOARD_COMMIT commit( m_frame ); // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( m_view ); @@ -1154,17 +1143,11 @@ int DRAWING_TOOL::drawZone( bool aKeepout ) zone->Outline()->CloseLastContour(); zone->Outline()->RemoveNullSegments(); - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( zone, UR_NEW ); - - m_board->Add( zone ); - m_view->Add( zone ); - if( !aKeepout ) static_cast( m_frame )->Fill_Zone( zone ); - zone->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - m_board->GetRatsnest()->Update( zone ); + commit.Add( zone ); + commit.Push( _( "Draw a zone" ) ); zone = NULL; } diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 7f5c4d5e70..732ac89d36 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -56,6 +56,8 @@ using namespace std::placeholders; #include #include +#include + EDIT_TOOL::EDIT_TOOL() : PCB_TOOL( "pcbnew.InteractiveEdit" ), m_selectionTool( NULL ), m_dragging( false ), m_undoInhibit( 0 ), m_updateFlag( KIGFX::VIEW_ITEM::NONE ) @@ -67,6 +69,9 @@ void EDIT_TOOL::Reset( RESET_REASON aReason ) { m_dragging = false; m_updateFlag = KIGFX::VIEW_ITEM::NONE; + + if( aReason != RUN ) + m_commit.reset( new BOARD_COMMIT( this ) ); } @@ -214,11 +219,10 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) lockOverride = true; // Save items, so changes can be undone - if( !isUndoInhibited() ) + selection.ForAll( [&](BOARD_ITEM* item) { - editFrame->OnModify(); - editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); - } + m_commit->Modify( item ); + } ); m_cursor = controls->GetCursorPosition(); @@ -243,6 +247,8 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) controls->SetAutoPan( true ); m_dragging = true; + + // Do not save intermediate modifications when an item is dragged incUndoInhibit(); } } @@ -254,6 +260,8 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) // Dispatch TOOL_ACTIONs else if( evt->Category() == TC_COMMAND ) { + wxPoint modPoint = getModificationPoint( selection ); + if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { Rotate( aEvent ); @@ -301,6 +309,14 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) //MoveExact( aEvent ); break; // exit the loop - we move exactly, so we have finished moving } + + if( m_dragging ) + { + // Update dragging offset (distance between cursor and the first dragged item) + m_offset = selection.Item( 0 )->GetPosition() - modPoint; + selection.group->ViewUpdate( KIGFX::VIEW_ITEM::ALL ); + updateRatsnest( true ); + } } else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) @@ -319,24 +335,13 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) m_offset.x = 0; m_offset.y = 0; - if( restore ) - { - // Modifications have to be rollbacked, so restore the previous state of items - wxCommandEvent dummy; - editFrame->RestoreCopyFromUndoList( dummy ); - } - else - { - // Changes are applied, so update the items - selection.group->ItemsViewUpdate( m_updateFlag ); - } - - if( unselect ) + if( unselect || restore ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); - RN_DATA* ratsnest = getModel()->GetRatsnest(); - ratsnest->ClearSimple(); - ratsnest->Recalculate(); + if( restore ) + m_commit->Revert(); + else + m_commit->Push( _( "Drag" ) ); controls->ShowCursor( false ); controls->SetAutoPan( false ); @@ -363,17 +368,8 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) if( dlg.ShowModal() ) { - RN_DATA* ratsnest = getModel()->GetRatsnest(); - - editFrame->OnModify(); - editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); - dlg.Apply(); - - selection.ForAll( std::bind( &KIGFX::VIEW_ITEM::ViewUpdate, - std::placeholders::_1, KIGFX::VIEW_ITEM::ALL ) ); - selection.ForAll( std::bind( &RN_DATA::Update, ratsnest, - std::placeholders::_1 ) ); - ratsnest->Recalculate(); + dlg.Apply( *m_commit ); + m_commit->Push( _( "Edit track/via properties" ) ); } } else if( selection.Size() == 1 ) // Properties are displayed when there is only one item selected @@ -381,34 +377,18 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) // Display properties dialog BOARD_ITEM* item = selection.Item( 0 ); - // Store the head of the undo list to compare if anything has changed - std::vector& undoList = editFrame->GetScreen()->m_UndoList.m_CommandsList; - // Some of properties dialogs alter pointers, so we should deselect them m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); + + // Store flags, so they can be restored later STATUS_FLAGS flags = item->GetFlags(); item->ClearFlags(); - // It is necessary to determine if anything has changed, so store the current undo save point - PICKED_ITEMS_LIST* undoSavePoint = undoList.empty() ? NULL : undoList.back(); - + // Do not handle undo buffer, it is done by the properties dialogs // Display properties dialog provided by the legacy canvas frame editFrame->OnEditItemRequest( NULL, item ); - if( !undoList.empty() && undoList.back() != undoSavePoint ) // Undo buffer has changed - { - // Process changes stored after undoSavePoint - processUndoBuffer( undoSavePoint ); - - // Update the modified item - item->ViewUpdate(); - RN_DATA* ratsnest = getModel()->GetRatsnest(); - ratsnest->Recalculate(); - - // TODO OBSERVER! I miss you so much.. - m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true ); - } - + m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true ); item->SetFlags( flags ); } @@ -432,37 +412,20 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) wxPoint rotatePoint = getModificationPoint( selection ); - // If it is being dragged, then it is already saved with UR_CHANGED flag - if( !isUndoInhibited() ) - { - editFrame->OnModify(); - editFrame->SaveCopyInUndoList( selection.items, UR_ROTATED, rotatePoint ); - } - for( unsigned int i = 0; i < selection.items.GetCount(); ++i ) { BOARD_ITEM* item = selection.Item( i ); - + m_commit->Modify( item ); item->Rotate( rotatePoint, editFrame->GetRotationAngle() ); - - if( !m_dragging ) - item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } - updateRatsnest( m_dragging ); - - // Update dragging offset (distance between cursor and the first dragged item) - m_offset = static_cast( selection.items.GetPickedItem( 0 ) )->GetPosition() - - rotatePoint; - - if( m_dragging ) - selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - else - getModel()->GetRatsnest()->Recalculate(); + if( !isUndoInhibited() ) + m_commit->Push( _( "Rotate" ) ); if( unselect ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); + // TODO selectionModified m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true ); return 0; @@ -472,7 +435,6 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent ) { const SELECTION& selection = m_selectionTool->GetSelection(); - PCB_BASE_FRAME* editFrame = getEditFrame(); // Shall the selection be cleared at the end? bool unselect = selection.Empty(); @@ -482,32 +444,15 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent ) wxPoint flipPoint = getModificationPoint( selection ); - if( !isUndoInhibited() ) // If it is being dragged, then it is already saved with UR_CHANGED flag - { - editFrame->OnModify(); - editFrame->SaveCopyInUndoList( selection.items, UR_FLIPPED, flipPoint ); - } - for( unsigned int i = 0; i < selection.items.GetCount(); ++i ) { BOARD_ITEM* item = selection.Item( i ); - + m_commit->Modify( item ); item->Flip( flipPoint ); - - if( !m_dragging ) - item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS ); } - updateRatsnest( m_dragging ); - - // Update dragging offset (distance between cursor and the first dragged item) - m_offset = static_cast( selection.items.GetPickedItem( 0 ) )->GetPosition() - - flipPoint; - - if( m_dragging ) - selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - else - getModel()->GetRatsnest()->Recalculate(); + if( !isUndoInhibited() ) + m_commit->Push( _( "Flip" ) ); if( unselect ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); @@ -520,94 +465,27 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent ) int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) { - const SELECTION& selection = m_selectionTool->GetSelection(); - if( !hoverSelection() || m_selectionTool->CheckLock() == SELECTION_LOCKED ) return 0; - // Get a copy of the selected items set - PICKED_ITEMS_LIST selectedItems = selection.items; - PCB_BASE_FRAME* editFrame = getEditFrame(); + // Get a copy instead of a reference, as we are going to clear current selection + SELECTION selection = m_selectionTool->GetSelection(); // As we are about to remove items, they have to be removed from the selection first m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); - editFrame->OnModify(); - editFrame->SaveCopyInUndoList( selectedItems, UR_DELETED ); + for( unsigned int i = 0; i < selection.items.GetCount(); ++i ) + { + BOARD_ITEM* item = selection.Item( i ); + m_commit->Remove( item ); + } - // And now remove - for( unsigned int i = 0; i < selectedItems.GetCount(); ++i ) - remove( static_cast( selectedItems.GetPickedItem( i ) ) ); - - getModel()->GetRatsnest()->Recalculate(); + m_commit->Push( _( "Delete" ) ); return 0; } -void EDIT_TOOL::remove( BOARD_ITEM* aItem ) -{ - BOARD* board = getModel(); - - switch( aItem->Type() ) - { - case PCB_MODULE_T: - { - MODULE* module = static_cast( aItem ); - module->ClearFlags(); - module->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, getView(), std::placeholders::_1 ) ); - - // Module itself is deleted after the switch scope is finished - // list of pads is rebuild by BOARD::BuildListOfNets() - - // Clear flags to indicate, that the ratsnest, list of nets & pads are not valid anymore - board->m_Status_Pcb = 0; - } - break; - - // Default removal procedure - case PCB_MODULE_TEXT_T: - { - TEXTE_MODULE* text = static_cast( aItem ); - - switch( text->GetType() ) - { - case TEXTE_MODULE::TEXT_is_REFERENCE: - DisplayError( getEditFrame(), _( "Cannot delete component reference." ) ); - return; - - case TEXTE_MODULE::TEXT_is_VALUE: - DisplayError( getEditFrame(), _( "Cannot delete component value." ) ); - return; - - case TEXTE_MODULE::TEXT_is_DIVERS: // suppress warnings - break; - } - } - - case PCB_PAD_T: - case PCB_MODULE_EDGE_T: - case PCB_LINE_T: // a segment not on copper layers - case PCB_TEXT_T: // a text on a layer - case PCB_TRACE_T: // a track segment (segment on a copper layer) - case PCB_VIA_T: // a via (like track segment on a copper layer) - case PCB_DIMENSION_T: // a dimension (graphic item) - case PCB_TARGET_T: // a target (graphic item) - case PCB_MARKER_T: // a marker used to show something - case PCB_ZONE_T: // SEG_ZONE items are now deprecated - case PCB_ZONE_AREA_T: - break; - - default: // other types do not need to (or should not) be handled - assert( false ); - return; - } - - getView()->Remove( aItem ); - getEditFrame()->GetModel()->Remove( aItem ); -} - - int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent ) { const SELECTION& selection = m_selectionTool->GetSelection(); @@ -628,13 +506,6 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent ) if( ret == wxID_OK ) { - if( !isUndoInhibited() ) - { - editFrame->OnModify(); - // Record an action of move and rotate - editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); - } - VECTOR2I rp = selection.GetCenter(); wxPoint rotPoint( rp.x, rp.y ); @@ -642,6 +513,7 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent ) { BOARD_ITEM* item = selection.Item( i ); + m_commit->Modify( item ); item->Move( translation ); item->Rotate( rotPoint, rotation ); @@ -649,12 +521,8 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent ) item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } - updateRatsnest( m_dragging ); - - if( m_dragging ) - selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - else - getModel()->GetRatsnest()->Recalculate(); + if( !isUndoInhibited() ) + m_commit->Push( _( "Move exact" ) ); if( unselect ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); @@ -681,9 +549,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) return 0; // we have a selection to work on now, so start the tool process - PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); - editFrame->OnModify(); // prevent other tools making undo points while the duplicate is going on // so that if you cancel, you don't get a duplicate object hiding over @@ -711,9 +577,8 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) BOARD_ITEM* new_item = NULL; - // TODO move DuplicateAndAddItem() to BOARD_ITEM_CONTAINER? dunno.. if( m_editModules ) - new_item = editFrame->GetBoard()->m_Modules->Duplicate( item, increment, true ); + new_item = editFrame->GetBoard()->m_Modules->Duplicate( item, increment ); else { #if 0 @@ -722,18 +587,12 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) // so zones are not duplicated if( item->Type() != PCB_ZONE_AREA_T ) #endif - new_item = editFrame->GetBoard()->Duplicate( item, true ); + new_item = editFrame->GetBoard()->Duplicate( item ); } if( new_item ) { - if( new_item->Type() == PCB_MODULE_T ) - { - static_cast( new_item )->RunOnChildren( std::bind( &KIGFX::VIEW::Add, - getView(), std::placeholders::_1 ) ); - } - - editFrame->GetGalCanvas()->GetView()->Add( new_item ); + m_commit->Add( new_item ); // Select the new item, so we can pick it up m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, new_item ); @@ -743,13 +602,11 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) // record the new items as added if( !selection.Empty() ) { - editFrame->SaveCopyInUndoList( selection.items, UR_NEW ); - editFrame->DisplayToolMsg( wxString::Format( _( "Duplicated %d item(s)" ), (int) old_items.size() ) ); // If items were duplicated, pick them up - // this works well for "dropping" copies around + // this works well for "dropping" copies around and pushes the commit TOOL_EVENT evt = COMMON_ACTIONS::editActivate.MakeEvent(); Main( evt ); } @@ -766,11 +623,9 @@ class GAL_ARRAY_CREATOR: public ARRAY_CREATOR public: GAL_ARRAY_CREATOR( PCB_BASE_FRAME& editFrame, bool editModules, - RN_DATA* ratsnest, const SELECTION& selection ): ARRAY_CREATOR( editFrame ), m_editModules( editModules ), - m_ratsnest( ratsnest ), m_selection( selection ) {} @@ -813,24 +668,13 @@ private: void postPushAction( BOARD_ITEM* new_item ) //override { - KIGFX::VIEW* view = m_parent.GetToolManager()->GetView(); - if( new_item->Type() == PCB_MODULE_T) - { - static_cast(new_item)->RunOnChildren( - std::bind(&KIGFX::VIEW::Add, view, std::placeholders::_1)); - } - - m_parent.GetGalCanvas()->GetView()->Add( new_item ); - m_ratsnest->Update( new_item ); } void finalise() // override { - m_ratsnest->Recalculate(); } bool m_editModules; - RN_DATA* m_ratsnest; const SELECTION& m_selection; }; @@ -846,14 +690,8 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) return 0; // we have a selection to work on now, so start the tool process - PCB_BASE_FRAME* editFrame = getEditFrame(); - editFrame->OnModify(); - - GAL_ARRAY_CREATOR array_creator( *editFrame, m_editModules, - getModel()->GetRatsnest(), - selection ); - + GAL_ARRAY_CREATOR array_creator( *editFrame, m_editModules, selection ); array_creator.Invoke(); return 0; @@ -937,73 +775,6 @@ bool EDIT_TOOL::hoverSelection( bool aSanitize ) } -void EDIT_TOOL::processUndoBuffer( const PICKED_ITEMS_LIST* aLastChange ) -{ - PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); - const std::vector& undoList = editFrame->GetScreen()->m_UndoList.m_CommandsList; - bool process = false; - - for( const PICKED_ITEMS_LIST* list : undoList ) - { - if( process ) - processPickedList( list ); - else if( list == aLastChange ) - process = true; // Start processing starting with the next undo save point - } - - // If we could not find the requested save point in the current undo list - // then the undo list must have been completely altered, so process everything - if( !process ) - { - for( const PICKED_ITEMS_LIST* list : undoList ) - processPickedList( list ); - } -} - - -void EDIT_TOOL::processPickedList( const PICKED_ITEMS_LIST* aList ) -{ - KIGFX::VIEW* view = getView(); - RN_DATA* ratsnest = getModel()->GetRatsnest(); - - for( unsigned int i = 0; i < aList->GetCount(); ++i ) - { - UNDO_REDO_T operation = aList->GetPickedItemStatus( i ); - BOARD_ITEM* updItem = static_cast( aList->GetPickedItem( i ) ); - - switch( operation ) - { - case UR_CHANGED: - ratsnest->Update( updItem ); - updItem->ViewUpdate( KIGFX::VIEW_ITEM::ALL ); - break; - - case UR_DELETED: - if( updItem->Type() == PCB_MODULE_T ) - static_cast( updItem )->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, - view, std::placeholders::_1 ) ); - - view->Remove( updItem ); - //ratsnest->Remove( updItem ); // this is done in BOARD::Remove - break; - - case UR_NEW: - if( updItem->Type() == PCB_MODULE_T ) - static_cast( updItem )->RunOnChildren( std::bind( &KIGFX::VIEW::Add, - view, std::placeholders::_1 ) ); - - view->Add( updItem ); - //ratsnest->Add( updItem ); // this is done in BOARD::Add - break; - - default: - assert( false ); // Not handled - break; - } - } -} - - int EDIT_TOOL::editFootprintInFpEditor( const TOOL_EVENT& aEvent ) { const SELECTION& selection = m_selectionTool->GetSelection(); @@ -1019,7 +790,7 @@ int EDIT_TOOL::editFootprintInFpEditor( const TOOL_EVENT& aEvent ) PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); - editFrame-> SetCurItem( mod ); + editFrame->SetCurItem( mod ); if( editFrame->GetCurItem()->GetTimeStamp() == 0 ) // Module Editor needs a non null timestamp { diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index 5f04c512a2..eb293af58f 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -30,6 +30,7 @@ #include #include +class BOARD_COMMIT; class BOARD_ITEM; class SELECTION_TOOL; @@ -135,9 +136,6 @@ private: /// Counter of undo inhibitions. When zero, undo is not inhibited. int m_undoInhibit; - ///> Removes and frees a single BOARD_ITEM. - void remove( BOARD_ITEM* aItem ); - ///> The required update flag for modified items KIGFX::VIEW_ITEM::VIEW_UPDATE_FLAGS m_updateFlag; @@ -216,6 +214,8 @@ private: BOARD_ITEM* item = selection.Item( 0 ); return dyn_cast( item ); } + + std::unique_ptr m_commit; }; #endif diff --git a/pcbnew/tools/module_tools.cpp b/pcbnew/tools/module_tools.cpp index 9848ede18b..d41f6e55f8 100644 --- a/pcbnew/tools/module_tools.cpp +++ b/pcbnew/tools/module_tools.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include using namespace std::placeholders; @@ -157,18 +158,17 @@ int MODULE_TOOLS::PlacePad( const TOOL_EVENT& aEvent ) else if( evt->IsClick( BUT_LEFT ) ) { - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( pad, UR_NEW ); + BOARD_COMMIT commit( m_frame ); + commit.Add( pad ); m_board->m_Status_Pcb = 0; // I have no clue why, but it is done in the legacy view - m_frame->GetModel()->Add( pad ); // Take the next available pad number pad->IncrementPadName( true, true ); // Handle the view aspect preview.Remove( pad ); - m_view->Add( pad ); + commit.Push( _( "Add a pad" ) ); // Start placing next pad pad = new D_PAD( m_board->m_Modules ); @@ -301,15 +301,17 @@ int MODULE_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent ) evt->IsDblClick( BUT_LEFT ) ) { // Accept changes + BOARD_COMMIT commit( m_frame ); m_frame->OnModify(); - m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_CHANGED ); for( D_PAD* pad : pads ) { + commit.Modify( pad ); pad->SetPadName( wxString::Format( wxT( "%s%d" ), padPrefix.c_str(), padNumber++ ) ); - pad->ViewUpdate(); } + commit.Push( _( "Enumerate pads" ) ); + break; } @@ -403,7 +405,6 @@ int MODULE_TOOLS::PasteItems( const TOOL_EVENT& aEvent ) { // Parse clipboard PCB_IO io( CTL_FOR_CLIPBOARD ); - MODULE* currentModule = m_board->m_Modules; MODULE* pastedModule = NULL; try @@ -469,8 +470,7 @@ int MODULE_TOOLS::PasteItems( const TOOL_EVENT& aEvent ) else if( evt->IsClick( BUT_LEFT ) ) { - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( currentModule, UR_CHANGED ); + BOARD_COMMIT commit( m_frame ); m_board->m_Status_Pcb = 0; // I have no clue why, but it is done in the legacy view @@ -480,8 +480,7 @@ int MODULE_TOOLS::PasteItems( const TOOL_EVENT& aEvent ) for( D_PAD* pad = pastedModule->Pads(); pad; pad = pad->Next() ) { D_PAD* clone = static_cast( pad->Clone() ); - currentModule->Add( clone ); - m_view->Add( clone ); + commit.Add( clone ); } for( BOARD_ITEM* drawing = pastedModule->GraphicalItems(); @@ -493,20 +492,17 @@ int MODULE_TOOLS::PasteItems( const TOOL_EVENT& aEvent ) { // Do not add reference/value - convert them to the common type text->SetType( TEXTE_MODULE::TEXT_is_DIVERS ); - currentModule->Add( text ); // Whyyyyyyyyyyyyyyyyyyyyyy?! All other items conform to rotation performed // on its parent module, but texts are so independent.. text->Rotate( text->GetPosition(), pastedModule->GetOrientation() ); - } - else if( EDGE_MODULE* edge = dyn_cast( clone ) ) - { - currentModule->Add( edge ); + commit.Add( text ); } - m_view->Add( clone ); + commit.Add( clone ); } + commit.Push( _( "Paste clipboard contents" ) ); preview.Clear(); break; diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index b5e50f06a4..dc4a4f589f 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -253,7 +254,6 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) module = NULL; preview.Clear(); - preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); controls->ShowCursor( true ); } else @@ -293,18 +293,12 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) // Add all the drawable parts to preview preview.Add( module ); module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) ); - - preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else { - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( module, UR_NEW ); - - // Place the selected module - module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1 ) ); - view->Add( module ); - module->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); + BOARD_COMMIT commit( m_frame ); + commit.Add( module ); + commit.Push( _( "Place a module" ) ); // Remove from preview preview.Remove( module ); @@ -416,7 +410,6 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent ) KIGFX::VIEW_GROUP preview( view ); preview.Add( target ); view->Add( &preview ); - preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); controls->SetSnapping( true ); @@ -454,12 +447,9 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent ) assert( target->GetSize() > 0 ); assert( target->GetWidth() > 0 ); - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( target, UR_NEW ); - - view->Add( target ); - board->Add( target ); - target->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); + BOARD_COMMIT commit( m_frame ); + commit.Add( target ); + commit.Push( _( "Place a layer alignment target" ) ); preview.Remove( target ); @@ -579,6 +569,7 @@ int PCB_EDITOR_CONTROL::ZoneMerge( const TOOL_EVENT& aEvent ) BOARD* board = getModel(); RN_DATA* ratsnest = board->GetRatsnest(); KIGFX::VIEW* view = getView(); + BOARD_COMMIT commit( m_frame ); if( selection.Size() < 2 ) return 0; @@ -646,7 +637,8 @@ int PCB_EDITOR_CONTROL::ZoneMerge( const TOOL_EVENT& aEvent ) } m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); - m_frame->SaveCopyInUndoList( changes, UR_UNSPECIFIED ); + + commit.Stage( changes ); for( unsigned i = 0; i < changes.GetCount(); ++i ) { @@ -660,11 +652,12 @@ int PCB_EDITOR_CONTROL::ZoneMerge( const TOOL_EVENT& aEvent ) } else if( picker.GetStatus() == UR_CHANGED ) { - item->ViewUpdate( KIGFX::VIEW_ITEM::ALL ); m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, item ); } } + commit.Push( _( "Merge zones" ) ); + return 0; } diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 48b06f4e83..32f72a89a2 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include using namespace std::placeholders; @@ -770,11 +771,10 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent ) { int open_ctl; wxString fileName; - PICKED_ITEMS_LIST undoListPicker; PCB_EDIT_FRAME* editFrame = dynamic_cast( m_frame ); BOARD* board = getModel(); - KIGFX::VIEW* view = getView(); + BOARD_COMMIT commit( editFrame ); if( !editFrame ) return 0; @@ -838,8 +838,7 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent ) continue; } - undoListPicker.PushItem( ITEM_PICKER( track, UR_NEW ) ); - view->Add( track ); + commit.Add( track ); m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, track ); } @@ -847,11 +846,7 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent ) for( ; module; module = module->Next() ) { - undoListPicker.PushItem( ITEM_PICKER( module, UR_NEW ) ); - - module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1 ) ); - view->Add( module ); - + commit.Add( module ); m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, module ); } @@ -859,24 +854,22 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent ) for( ; drawing; drawing = drawing->Next() ) { - undoListPicker.PushItem( ITEM_PICKER( drawing, UR_NEW ) ); - view->Add( drawing ); + commit.Add( drawing ); m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, drawing ); } for( ZONE_CONTAINER* zone = board->GetArea( zonescount ); zone; zone = board->GetArea( zonescount ) ) { - undoListPicker.PushItem( ITEM_PICKER( zone, UR_NEW ) ); - zonescount++; - view->Add( zone ); + ++zonescount; + commit.Add( zone ); m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, zone ); } - if( undoListPicker.GetCount() == 0 ) + if( commit.Empty() ) return 0; - editFrame->SaveCopyInUndoList( undoListPicker, UR_NEW ); + commit.Push( _( "Append a board" ) ); // Synchronize layers // we should not ask PLUGINs to do these items: @@ -900,7 +893,9 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent ) board->GetRatsnest()->Recalculate(); // Start dragging the appended board - VECTOR2D v( static_cast( undoListPicker.GetPickedItem( 0 ) )->GetPosition() ); + SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); + const SELECTION& selection = selectionTool->GetSelection(); + VECTOR2D v( selection.Item( 0 )->GetPosition() ); getViewControls()->WarpCursor( v, true, true ); m_toolMgr->InvokeTool( "pcbnew.InteractiveEdit" ); diff --git a/pcbnew/tools/placement_tool.cpp b/pcbnew/tools/placement_tool.cpp index 8452d18816..c5c6a5d723 100644 --- a/pcbnew/tools/placement_tool.cpp +++ b/pcbnew/tools/placement_tool.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2014 CERN + * Copyright (C) 2014-2016 CERN * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -75,39 +76,34 @@ int PLACEMENT_TOOL::AlignTop( const TOOL_EVENT& aEvent ) { const SELECTION& selection = m_selectionTool->GetSelection(); - if( selection.Size() > 1 ) + if( selection.Size() <= 1 ) + return 0; + + BOARD_COMMIT commit( getEditFrame() ); + commit.Stage( selection.items, UR_CHANGED ); + + // Compute the highest point of selection - it will be the edge of alignment + int top = selection.Item( 0 )->GetBoundingBox().GetY(); + + for( int i = 1; i < selection.Size(); ++i ) { - PCB_BASE_FRAME* editFrame = getEditFrame(); - RN_DATA* ratsnest = getModel()->GetRatsnest(); + int currentTop = selection.Item( i )->GetBoundingBox().GetY(); - editFrame->OnModify(); - editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); - - // Compute the highest point of selection - it will be the edge of alignment - int top = selection.Item( 0 )->GetBoundingBox().GetY(); - - for( int i = 1; i < selection.Size(); ++i ) - { - int currentTop = selection.Item( i )->GetBoundingBox().GetY(); - - if( top > currentTop ) // Y decreases when going up - top = currentTop; - } - - // Move the selected items - for( int i = 0; i < selection.Size(); ++i ) - { - BOARD_ITEM* item = selection.Item( i ); - int difference = top - item->GetBoundingBox().GetY(); - - item->Move( wxPoint( 0, difference ) ); - item->ViewUpdate(); - ratsnest->Update( item ); - } - - getModel()->GetRatsnest()->Recalculate(); + if( top > currentTop ) // Y decreases when going up + top = currentTop; } + // Move the selected items + for( int i = 0; i < selection.Size(); ++i ) + { + BOARD_ITEM* item = selection.Item( i ); + int difference = top - item->GetBoundingBox().GetY(); + + item->Move( wxPoint( 0, difference ) ); + } + + commit.Push( _( "Align to top" ) ); + return 0; } @@ -116,39 +112,34 @@ int PLACEMENT_TOOL::AlignBottom( const TOOL_EVENT& aEvent ) { const SELECTION& selection = m_selectionTool->GetSelection(); - if( selection.Size() > 1 ) + if( selection.Size() <= 1 ) + return 0; + + BOARD_COMMIT commit( getEditFrame() ); + commit.Stage( selection.items, UR_CHANGED ); + + // Compute the lowest point of selection - it will be the edge of alignment + int bottom = selection.Item( 0 )->GetBoundingBox().GetBottom(); + + for( int i = 1; i < selection.Size(); ++i ) { - PCB_BASE_FRAME* editFrame = getEditFrame(); - RN_DATA* ratsnest = getModel()->GetRatsnest(); + int currentBottom = selection.Item( i )->GetBoundingBox().GetBottom(); - editFrame->OnModify(); - editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); - - // Compute the lowest point of selection - it will be the edge of alignment - int bottom = selection.Item( 0 )->GetBoundingBox().GetBottom(); - - for( int i = 1; i < selection.Size(); ++i ) - { - int currentBottom = selection.Item( i )->GetBoundingBox().GetBottom(); - - if( bottom < currentBottom ) // Y increases when going down - bottom = currentBottom; - } - - // Move the selected items - for( int i = 0; i < selection.Size(); ++i ) - { - BOARD_ITEM* item = selection.Item( i ); - int difference = bottom - item->GetBoundingBox().GetBottom(); - - item->Move( wxPoint( 0, difference ) ); - item->ViewUpdate(); - ratsnest->Update( item ); - } - - getModel()->GetRatsnest()->Recalculate(); + if( bottom < currentBottom ) // Y increases when going down + bottom = currentBottom; } + // Move the selected items + for( int i = 0; i < selection.Size(); ++i ) + { + BOARD_ITEM* item = selection.Item( i ); + int difference = bottom - item->GetBoundingBox().GetBottom(); + + item->Move( wxPoint( 0, difference ) ); + } + + commit.Push( _( "Align to bottom" ) ); + return 0; } @@ -157,39 +148,34 @@ int PLACEMENT_TOOL::AlignLeft( const TOOL_EVENT& aEvent ) { const SELECTION& selection = m_selectionTool->GetSelection(); - if( selection.Size() > 1 ) + if( selection.Size() <= 1 ) + return 0; + + BOARD_COMMIT commit( getEditFrame() ); + commit.Stage( selection.items, UR_CHANGED ); + + // Compute the leftmost point of selection - it will be the edge of alignment + int left = selection.Item( 0 )->GetBoundingBox().GetX(); + + for( int i = 1; i < selection.Size(); ++i ) { - PCB_BASE_FRAME* editFrame = getEditFrame(); - RN_DATA* ratsnest = getModel()->GetRatsnest(); + int currentLeft = selection.Item( i )->GetBoundingBox().GetX(); - editFrame->OnModify(); - editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); - - // Compute the leftmost point of selection - it will be the edge of alignment - int left = selection.Item( 0 )->GetBoundingBox().GetX(); - - for( int i = 1; i < selection.Size(); ++i ) - { - int currentLeft = selection.Item( i )->GetBoundingBox().GetX(); - - if( left > currentLeft ) // X decreases when going left - left = currentLeft; - } - - // Move the selected items - for( int i = 0; i < selection.Size(); ++i ) - { - BOARD_ITEM* item = selection.Item( i ); - int difference = left - item->GetBoundingBox().GetX(); - - item->Move( wxPoint( difference, 0 ) ); - item->ViewUpdate(); - ratsnest->Update( item ); - } - - getModel()->GetRatsnest()->Recalculate(); + if( left > currentLeft ) // X decreases when going left + left = currentLeft; } + // Move the selected items + for( int i = 0; i < selection.Size(); ++i ) + { + BOARD_ITEM* item = selection.Item( i ); + int difference = left - item->GetBoundingBox().GetX(); + + item->Move( wxPoint( difference, 0 ) ); + } + + commit.Push( _( "Align to left" ) ); + return 0; } @@ -198,39 +184,34 @@ int PLACEMENT_TOOL::AlignRight( const TOOL_EVENT& aEvent ) { const SELECTION& selection = m_selectionTool->GetSelection(); - if( selection.Size() > 1 ) + if( selection.Size() <= 1 ) + return 0; + + BOARD_COMMIT commit( getEditFrame() ); + commit.Stage( selection.items, UR_CHANGED ); + + // Compute the rightmost point of selection - it will be the edge of alignment + int right = selection.Item( 0 )->GetBoundingBox().GetRight(); + + for( int i = 1; i < selection.Size(); ++i ) { - PCB_BASE_FRAME* editFrame = getEditFrame(); - RN_DATA* ratsnest = getModel()->GetRatsnest(); + int currentRight = selection.Item( i )->GetBoundingBox().GetRight(); - editFrame->OnModify(); - editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); - - // Compute the rightmost point of selection - it will be the edge of alignment - int right = selection.Item( 0 )->GetBoundingBox().GetRight(); - - for( int i = 1; i < selection.Size(); ++i ) - { - int currentRight = selection.Item( i )->GetBoundingBox().GetRight(); - - if( right < currentRight ) // X increases when going right - right = currentRight; - } - - // Move the selected items - for( int i = 0; i < selection.Size(); ++i ) - { - BOARD_ITEM* item = selection.Item( i ); - int difference = right - item->GetBoundingBox().GetRight(); - - item->Move( wxPoint( difference, 0 ) ); - item->ViewUpdate(); - ratsnest->Update( item ); - } - - getModel()->GetRatsnest()->Recalculate(); + if( right < currentRight ) // X increases when going right + right = currentRight; } + // Move the selected items + for( int i = 0; i < selection.Size(); ++i ) + { + BOARD_ITEM* item = selection.Item( i ); + int difference = right - item->GetBoundingBox().GetRight(); + + item->Move( wxPoint( difference, 0 ) ); + } + + commit.Push( _( "Align to right" ) ); + return 0; } @@ -251,45 +232,40 @@ int PLACEMENT_TOOL::DistributeHorizontally( const TOOL_EVENT& aEvent ) { const SELECTION& selection = m_selectionTool->GetSelection(); - if( selection.Size() > 1 ) + if( selection.Size() <= 1 ) + return 0; + + BOARD_COMMIT commit( getEditFrame() ); + commit.Stage( selection.items, UR_CHANGED ); + + // Prepare a list, so the items can be sorted by their X coordinate + std::list itemsList; + for( int i = 0; i < selection.Size(); ++i ) + itemsList.push_back( selection.Item( i ) ); + + // Sort items by X coordinate + itemsList.sort( compareX ); + + // Expected X coordinate for the next item (=minX) + int position = (*itemsList.begin())->GetBoundingBox().Centre().x; + + // X coordinate for the last item + const int maxX = (*itemsList.rbegin())->GetBoundingBox().Centre().x; + + // Distance between items + const int distance = ( maxX - position ) / ( itemsList.size() - 1 ); + + for( BOARD_ITEM* item : itemsList ) { - PCB_BASE_FRAME* editFrame = getEditFrame(); - RN_DATA* ratsnest = getModel()->GetRatsnest(); + int difference = position - item->GetBoundingBox().Centre().x; - editFrame->OnModify(); - editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); + item->Move( wxPoint( difference, 0 ) ); - // Prepare a list, so the items can be sorted by their X coordinate - std::list itemsList; - for( int i = 0; i < selection.Size(); ++i ) - itemsList.push_back( selection.Item( i ) ); - - // Sort items by X coordinate - itemsList.sort( compareX ); - - // Expected X coordinate for the next item (=minX) - int position = (*itemsList.begin())->GetBoundingBox().Centre().x; - - // X coordinate for the last item - const int maxX = (*itemsList.rbegin())->GetBoundingBox().Centre().x; - - // Distance between items - const int distance = ( maxX - position ) / ( itemsList.size() - 1 ); - - for( BOARD_ITEM* item : itemsList ) - { - int difference = position - item->GetBoundingBox().Centre().x; - - item->Move( wxPoint( difference, 0 ) ); - item->ViewUpdate(); - ratsnest->Update( item ); - - position += distance; - } - - getModel()->GetRatsnest()->Recalculate(); + position += distance; } + commit.Push( _( "Distribute horizontally" ) ); + return 0; } @@ -298,45 +274,40 @@ int PLACEMENT_TOOL::DistributeVertically( const TOOL_EVENT& aEvent ) { const SELECTION& selection = m_selectionTool->GetSelection(); - if( selection.Size() > 1 ) + if( selection.Size() <= 1 ) + return 0; + + BOARD_COMMIT commit( getEditFrame() ); + commit.Stage( selection.items, UR_CHANGED ); + + // Prepare a list, so the items can be sorted by their Y coordinate + std::list itemsList; + for( int i = 0; i < selection.Size(); ++i ) + itemsList.push_back( selection.Item( i ) ); + + // Sort items by Y coordinate + itemsList.sort( compareY ); + + // Expected Y coordinate for the next item (=minY) + int position = (*itemsList.begin())->GetBoundingBox().Centre().y; + + // Y coordinate for the last item + const int maxY = (*itemsList.rbegin())->GetBoundingBox().Centre().y; + + // Distance between items + const int distance = ( maxY - position ) / ( itemsList.size() - 1 ); + + for( BOARD_ITEM* item : itemsList ) { - PCB_BASE_FRAME* editFrame = getEditFrame(); - RN_DATA* ratsnest = getModel()->GetRatsnest(); + int difference = position - item->GetBoundingBox().Centre().y; - editFrame->OnModify(); - editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); + item->Move( wxPoint( 0, difference ) ); - // Prepare a list, so the items can be sorted by their Y coordinate - std::list itemsList; - for( int i = 0; i < selection.Size(); ++i ) - itemsList.push_back( selection.Item( i ) ); - - // Sort items by Y coordinate - itemsList.sort( compareY ); - - // Expected Y coordinate for the next item (=minY) - int position = (*itemsList.begin())->GetBoundingBox().Centre().y; - - // Y coordinate for the last item - const int maxY = (*itemsList.rbegin())->GetBoundingBox().Centre().y; - - // Distance between items - const int distance = ( maxY - position ) / ( itemsList.size() - 1 ); - - for( BOARD_ITEM* item : itemsList ) - { - int difference = position - item->GetBoundingBox().Centre().y; - - item->Move( wxPoint( 0, difference ) ); - item->ViewUpdate(); - ratsnest->Update( item ); - - position += distance; - } - - getModel()->GetRatsnest()->Recalculate(); + position += distance; } + commit.Push( _( "Distribute vertically" ) ); + return 0; } diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 1ce88ab153..0386c6d50c 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -34,6 +34,7 @@ using namespace std::placeholders; #include "common_actions.h" #include "selection_tool.h" #include "point_editor.h" +#include #include #include @@ -259,6 +260,8 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) m_editedPoint = NULL; bool modified = false; + BOARD_COMMIT commit( editFrame ); + // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { @@ -292,8 +295,7 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) { if( !modified ) { - editFrame->OnModify(); - editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); + commit.Stage( selection.items, UR_CHANGED ); controls->ForceCursorPosition( false ); m_original = *m_editedPoint; // Save the original position @@ -302,6 +304,7 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) } bool enableAltConstraint = !!evt->Modifier( MD_CTRL ); + if( enableAltConstraint != (bool) m_altConstraint ) // alternative constraint setAltConstraint( enableAltConstraint ); @@ -314,10 +317,9 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) updateItem(); updatePoints(); - - m_editPoints->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } + // TODO necessary? else if( evt->IsAction( &COMMON_ACTIONS::pointEditorUpdate ) ) { updatePoints(); @@ -327,7 +329,13 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) { controls->SetAutoPan( false ); setAltConstraint( false ); - modified = false; + + if( modified ) + { + commit.Push( _( "Drag a line ending" ) ); + modified = false; + } + m_toolMgr->PassEvent(); } @@ -335,9 +343,7 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) { if( modified ) // Restore the last change { - wxCommandEvent dummy; - editFrame->RestoreCopyFromUndoList( dummy ); - + commit.Revert(); updatePoints(); modified = false; } @@ -357,7 +363,6 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) if( m_editPoints ) { finishItem(); - item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); view->Remove( m_editPoints.get() ); m_editPoints.reset(); } @@ -615,6 +620,8 @@ void POINT_EDITOR::updatePoints() default: break; } + + m_editPoints->ViewUpdate(); } @@ -719,17 +726,16 @@ EDIT_POINT POINT_EDITOR::get45DegConstrainer() const void POINT_EDITOR::addCorner( const VECTOR2I& aBreakPoint ) { EDA_ITEM* item = m_editPoints->GetParent(); - const SELECTION& selection = m_selectionTool->GetSelection(); PCB_BASE_EDIT_FRAME* frame = getEditFrame(); + BOARD_COMMIT commit( frame ); if( item->Type() == PCB_ZONE_AREA_T ) { - frame->OnModify(); - frame->SaveCopyInUndoList( selection.items, UR_CHANGED ); - ZONE_CONTAINER* zone = static_cast( item ); CPolyLine* outline = zone->Outline(); + commit.Modify( zone ); + // Handle the last segment, so other segments can be easily handled in a loop unsigned int nearestIdx = outline->GetCornersCount() - 1, nextNearestIdx = 0; SEG side( VECTOR2I( outline->GetPos( nearestIdx ) ), @@ -761,6 +767,8 @@ void POINT_EDITOR::addCorner( const VECTOR2I& aBreakPoint ) nearestPoint = ( sideOrigin + sideEnd ) / 2; outline->InsertCorner( nearestIdx, nearestPoint.x, nearestPoint.y ); + + commit.Push( _( "Add a zone corner" ) ); } else if( item->Type() == PCB_LINE_T || item->Type() == PCB_MODULE_EDGE_T ) @@ -771,8 +779,8 @@ void POINT_EDITOR::addCorner( const VECTOR2I& aBreakPoint ) if( segment->GetShape() == S_SEGMENT ) { - ITEM_PICKER old_segment( segment, UR_CHANGED ); - old_segment.SetLink( segment->Clone() ); + BOARD_COMMIT commit( frame ); + commit.Modify( segment ); SEG seg( segment->GetStart(), segment->GetEnd() ); VECTOR2I nearestPoint = seg.NearestPoint( aBreakPoint ); @@ -799,14 +807,8 @@ void POINT_EDITOR::addCorner( const VECTOR2I& aBreakPoint ) newSegment->SetStart( wxPoint( nearestPoint.x, nearestPoint.y ) ); newSegment->SetEnd( wxPoint( seg.B.x, seg.B.y ) ); - PICKED_ITEMS_LIST changes; - changes.PushItem( old_segment ); - changes.PushItem( ITEM_PICKER( newSegment, UR_NEW ) ); - frame->OnModify(); - frame->SaveCopyInUndoList( changes, UR_UNSPECIFIED ); - - frame->GetModel()->Add( newSegment ); - getView()->Add( newSegment ); + commit.Add( newSegment ); + commit.Push( _( "Split segment" ) ); } } } @@ -818,21 +820,20 @@ void POINT_EDITOR::removeCorner( EDIT_POINT* aPoint ) if( item->Type() == PCB_ZONE_AREA_T ) { - const SELECTION& selection = m_selectionTool->GetSelection(); PCB_BASE_FRAME* frame = getEditFrame(); + BOARD_COMMIT commit( frame ); ZONE_CONTAINER* zone = static_cast( item ); CPolyLine* outline = zone->Outline(); + commit.Modify( zone ); for( int i = 0; i < outline->GetCornersCount(); ++i ) { if( VECTOR2I( outline->GetPos( i ) ) == aPoint->GetPosition() ) { - frame->OnModify(); - frame->SaveCopyInUndoList( selection.items, UR_CHANGED ); - outline->DeleteCorner( i ); setEditedPoint( NULL ); + commit.Push( _( "Remove a zone corner" ) ); break; } } diff --git a/pcbnew/zones_by_polygon.cpp b/pcbnew/zones_by_polygon.cpp index 2ea54c104f..f6c45d0f06 100644 --- a/pcbnew/zones_by_polygon.cpp +++ b/pcbnew/zones_by_polygon.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -859,13 +860,14 @@ void PCB_EDIT_FRAME::Edit_Zone_Params( wxDC* DC, ZONE_CONTAINER* aZone ) ZONE_EDIT_T edited; ZONE_SETTINGS zoneInfo = GetZoneSettings(); + BOARD_COMMIT commit( this ); m_canvas->SetIgnoreMouseEvents( true ); // Save initial zones configuration, for undo/redo, before adding new zone // note the net name and the layer can be changed, so we must save all zones s_AuxiliaryList.ClearListAndDeleteItems(); s_PickedList.ClearListAndDeleteItems(); - SaveCopyOfZones(s_PickedList, GetBoard(), -1, UNDEFINED_LAYER ); + SaveCopyOfZones( s_PickedList, GetBoard(), -1, UNDEFINED_LAYER ); if( aZone->GetIsKeepout() ) { @@ -901,7 +903,8 @@ void PCB_EDIT_FRAME::Edit_Zone_Params( wxDC* DC, ZONE_CONTAINER* aZone ) if( edited == ZONE_EXPORT_VALUES ) { UpdateCopyOfZonesList( s_PickedList, s_AuxiliaryList, GetBoard() ); - SaveCopyInUndoList(s_PickedList, UR_UNSPECIFIED); + commit.Stage( s_PickedList ); + commit.Push( _( "Modify zone properties" ) ); s_PickedList.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items return; } @@ -927,11 +930,10 @@ void PCB_EDIT_FRAME::Edit_Zone_Params( wxDC* DC, ZONE_CONTAINER* aZone ) GetBoard()->RedrawAreasOutlines( m_canvas, DC, GR_OR, UNDEFINED_LAYER ); UpdateCopyOfZonesList( s_PickedList, s_AuxiliaryList, GetBoard() ); - SaveCopyInUndoList(s_PickedList, UR_UNSPECIFIED); + commit.Stage( s_PickedList ); + commit.Push( _( "Modify zone properties" ) ); s_PickedList.ClearItemsList(); // s_ItemsListPicker is no longer owner of picked items - - OnModify(); } From 86895822b7056c0e49e897e19cfdf26f4c63e242 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 21 Jun 2016 17:35:30 +0200 Subject: [PATCH 39/61] BOARD_COMMIT retracts changes in reversed order --- pcbnew/board_commit.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index d379a93708..d2fcfc050b 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -277,8 +277,9 @@ void BOARD_COMMIT::Revert() BOARD* board = (BOARD*) m_toolMgr->GetModel(); RN_DATA* ratsnest = board->GetRatsnest(); - for( COMMIT_LINE& ent : m_changes ) + for( auto it = m_changes.rbegin(); it != m_changes.rend(); ++it ) { + COMMIT_LINE& ent = *it; BOARD_ITEM* item = static_cast( ent.m_item ); BOARD_ITEM* copy = static_cast( ent.m_copy ); From ad1111748ebaa5d18affbbc251ffaa4db7edd801 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 21 Jun 2016 17:36:00 +0200 Subject: [PATCH 40/61] Removed 'undo inhibit' in EDIT_TOOL --- pcbnew/tools/edit_tool.cpp | 26 ++++------------------ pcbnew/tools/edit_tool.h | 44 -------------------------------------- 2 files changed, 4 insertions(+), 66 deletions(-) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 732ac89d36..b7c06a7d40 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -60,7 +60,7 @@ using namespace std::placeholders; EDIT_TOOL::EDIT_TOOL() : PCB_TOOL( "pcbnew.InteractiveEdit" ), m_selectionTool( NULL ), - m_dragging( false ), m_undoInhibit( 0 ), m_updateFlag( KIGFX::VIEW_ITEM::NONE ) + m_dragging( false ), m_updateFlag( KIGFX::VIEW_ITEM::NONE ) { } @@ -115,9 +115,6 @@ bool EDIT_TOOL::invokeInlineRouter() TRACK* track = uniqueSelected(); VIA* via = uniqueSelected(); - if( isUndoInhibited() ) - return false; - if( track || via ) { ROUTER_TOOL* theRouter = static_cast( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) ); @@ -247,9 +244,6 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) controls->SetAutoPan( true ); m_dragging = true; - - // Do not save intermediate modifications when an item is dragged - incUndoInhibit(); } } @@ -328,9 +322,6 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) } } while( ( evt = Wait() ) ); //Should be assignment not equality test - if( m_dragging ) - decUndoInhibit(); - m_dragging = false; m_offset.x = 0; m_offset.y = 0; @@ -419,7 +410,7 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) item->Rotate( rotatePoint, editFrame->GetRotationAngle() ); } - if( !isUndoInhibited() ) + if( !m_dragging ) m_commit->Push( _( "Rotate" ) ); if( unselect ) @@ -451,7 +442,7 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent ) item->Flip( flipPoint ); } - if( !isUndoInhibited() ) + if( !m_dragging ) m_commit->Push( _( "Flip" ) ); if( unselect ) @@ -521,8 +512,7 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent ) item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } - if( !isUndoInhibited() ) - m_commit->Push( _( "Move exact" ) ); + m_commit->Push( _( "Move exact" ) ); if( unselect ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); @@ -551,11 +541,6 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) // we have a selection to work on now, so start the tool process PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); - // prevent other tools making undo points while the duplicate is going on - // so that if you cancel, you don't get a duplicate object hiding over - // the original - incUndoInhibit(); - std::vector old_items; for( int i = 0; i < selection.Size(); ++i ) @@ -611,9 +596,6 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) Main( evt ); } - // and re-enable undos - decUndoInhibit(); - return 0; }; diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index eb293af58f..640caf569b 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -133,9 +133,6 @@ private: ///> of edit reference point). VECTOR2I m_cursor; - /// Counter of undo inhibitions. When zero, undo is not inhibited. - int m_undoInhibit; - ///> The required update flag for modified items KIGFX::VIEW_ITEM::VIEW_UPDATE_FLAGS m_updateFlag; @@ -159,47 +156,6 @@ private: ///> the cursor or displays a disambiguation menu if there are multiple items. bool hoverSelection( bool aSanitize = true ); - ///> Processes the current undo buffer since the last change. If the last change does not occur - ///> in the current buffer, then the whole list is processed. - void processUndoBuffer( const PICKED_ITEMS_LIST* aLastChange ); - - ///> Updates items stored in the list. - void processPickedList( const PICKED_ITEMS_LIST* aList ); - - /** - * Increments the undo inhibit counter. This will indicate that tools - * should not create an undo point, as another tool is doing it already, - * and considers that its operation is atomic, even if it calls another one - * (for example a duplicate calls a move). - */ - inline void incUndoInhibit() - { - m_undoInhibit++; - } - - /** - * Decrements the inhibit counter. An assert is raised if the counter drops - * below zero. - */ - inline void decUndoInhibit() - { - m_undoInhibit--; - - wxASSERT_MSG( m_undoInhibit >= 0, wxT( "Undo inhibit count decremented past zero" ) ); - } - - /** - * Report if the tool manager has been told at least once that undo - * points should not be created. This can be ignored if the undo point - * is still required. - * - * @return true if undo are inhibited - */ - inline bool isUndoInhibited() const - { - return m_undoInhibit > 0; - } - int editFootprintInFpEditor( const TOOL_EVENT& aEvent ); bool invokeInlineRouter(); From 303a6928ab07087482e3dad708a6486d6c156d25 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 23 Jun 2016 09:26:21 +0200 Subject: [PATCH 41/61] Changed pointEditorUpdate to editModifiedSelection. --- pcbnew/tools/common_actions.cpp | 8 ++++---- pcbnew/tools/common_actions.h | 6 +++--- pcbnew/tools/edit_tool.cpp | 10 +++++----- pcbnew/tools/point_editor.cpp | 3 +-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 4d52d39043..b9af35915a 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -138,6 +138,10 @@ TOOL_ACTION COMMON_ACTIONS::properties( "pcbnew.InteractiveEdit.properties", AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_EDIT_ITEM ), _( "Properties..." ), _( "Displays item properties dialog" ), editor_xpm ); +TOOL_ACTION COMMON_ACTIONS::editModifiedSelection( "pcbnew.InteractiveEdit.ModifiedSelection", + AS_GLOBAL, 0, + "", "" ); + // Drawing tool actions TOOL_ACTION COMMON_ACTIONS::drawLine( "pcbnew.InteractiveDrawing.line", @@ -564,10 +568,6 @@ TOOL_ACTION COMMON_ACTIONS::routerInlineDrag( "pcbnew.InteractiveRouter.InlineDr "", "" ); // Point editor -TOOL_ACTION COMMON_ACTIONS::pointEditorUpdate( "pcbnew.PointEditor.update", - AS_GLOBAL, 0, - "", "" ); // No description, it is not supposed to be shown anywhere - TOOL_ACTION COMMON_ACTIONS::pointEditorAddCorner( "pcbnew.PointEditor.addCorner", AS_GLOBAL, 0, _( "Create corner" ), _( "Create corner" ), add_corner_xpm ); diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index 3f69ac20a6..962b6b436f 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -79,6 +79,9 @@ public: /// Activation of the edit tool static TOOL_ACTION properties; + /// Modified selection notification + static TOOL_ACTION editModifiedSelection; + /// Activation of the exact move tool static TOOL_ACTION moveExact; @@ -161,9 +164,6 @@ public: static TOOL_ACTION routerInlineDrag; // Point Editor - /// Update edit points - static TOOL_ACTION pointEditorUpdate; - /// Break outline (insert additional points to an edge) static TOOL_ACTION pointEditorAddCorner; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index b7c06a7d40..ef1288ee11 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -248,7 +248,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) } selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true ); + m_toolMgr->RunAction( COMMON_ACTIONS::editModifiedSelection, true ); } // Dispatch TOOL_ACTIONs @@ -379,7 +379,7 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) // Display properties dialog provided by the legacy canvas frame editFrame->OnEditItemRequest( NULL, item ); - m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true ); + m_toolMgr->RunAction( COMMON_ACTIONS::editModifiedSelection, true ); item->SetFlags( flags ); } @@ -417,7 +417,7 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); // TODO selectionModified - m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true ); + m_toolMgr->RunAction( COMMON_ACTIONS::editModifiedSelection, true ); return 0; } @@ -448,7 +448,7 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent ) if( unselect ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); - m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true ); + m_toolMgr->RunAction( COMMON_ACTIONS::editModifiedSelection, true ); return 0; } @@ -517,7 +517,7 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent ) if( unselect ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); - m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true ); + m_toolMgr->RunAction( COMMON_ACTIONS::editModifiedSelection, true ); } return 0; diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 0386c6d50c..48705ae7cc 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -319,8 +319,7 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) updatePoints(); } - // TODO necessary? - else if( evt->IsAction( &COMMON_ACTIONS::pointEditorUpdate ) ) + else if( evt->IsAction( &COMMON_ACTIONS::editModifiedSelection ) ) { updatePoints(); } From 91ea4242ca86346779840c6e6a65e9ea2a6dcf8b Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 16 Aug 2016 16:56:20 +0200 Subject: [PATCH 42/61] Fixed freeze after adding a module --- pcbnew/tools/pcb_editor_control.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index dc4a4f589f..b72d770865 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -250,7 +250,7 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) { if( module ) { - board->Delete( module ); // it was added by LoadModuleFromLibrary() + delete module; module = NULL; preview.Clear(); @@ -285,9 +285,13 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) module = m_frame->LoadModuleFromLibrary( wxEmptyString, m_frame->Prj().PcbFootprintLibs(), true, NULL ); + if( module == NULL ) continue; + // Module has been added in LoadModuleFromLibrary(), + // so we have to remove it before committing the change @todo LEGACY + board->Remove( module ); module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); // Add all the drawable parts to preview From 6701b80f772c000297dd74910666b1065fe58858 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 17 Aug 2016 17:24:04 +0200 Subject: [PATCH 43/61] Converted global deletion, global text size setting & module exchange to BOARD_COMMIT. --- include/wxPcbStruct.h | 7 +- pcbnew/dialogs/dialog_global_deletion.cpp | 52 +++-------- .../dialog_global_modules_fields_edition.cpp | 86 +++++-------------- pcbnew/modedit.cpp | 8 +- pcbnew/tools/edit_tool.cpp | 2 +- pcbnew/xchgmod.cpp | 40 +++------ 6 files changed, 55 insertions(+), 140 deletions(-) diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 4463c40664..356495f925 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -39,6 +39,7 @@ /* Forward declarations of classes. */ class PCB_SCREEN; class BOARD; +class BOARD_COMMIT; class BOARD_ITEM_CONTAINER; class TEXTE_PCB; class MODULE; @@ -1088,11 +1089,9 @@ public: * OldModule is deleted or put in undo list. * @param aOldModule = footprint to replace * @param aNewModule = footprint to put - * @param aUndoPickList = the undo list used to save OldModule. If null, - * OldModule is deleted + * @param aCommit = commit that should store the changes */ - void Exchange_Module( MODULE* aOldModule, MODULE* aNewModule, - PICKED_ITEMS_LIST* aUndoPickList ); + void Exchange_Module( MODULE* aOldModule, MODULE* aNewModule, BOARD_COMMIT& aCommit ); // loading modules: see PCB_BASE_FRAME diff --git a/pcbnew/dialogs/dialog_global_deletion.cpp b/pcbnew/dialogs/dialog_global_deletion.cpp index cbbc61b973..6c36cad2d6 100644 --- a/pcbnew/dialogs/dialog_global_deletion.cpp +++ b/pcbnew/dialogs/dialog_global_deletion.cpp @@ -30,6 +30,7 @@ using namespace std::placeholders; #include #include #include +#include #include #include @@ -108,11 +109,9 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete() return; BOARD* pcb = m_Parent->GetBoard(); - PICKED_ITEMS_LIST pickersList; - ITEM_PICKER itemPicker( NULL, UR_DELETED ); + BOARD_COMMIT commit( m_Parent ); BOARD_ITEM* item; BOARD_ITEM* nextitem; - RN_DATA* ratsnest = pcb->GetRatsnest(); LSET layers_filter = LSET().set(); @@ -128,11 +127,7 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete() { if( delAll || layers_filter[item->GetLayer()] ) { - itemPicker.SetItem( item ); - pickersList.PushItem( itemPicker ); - pcb->Remove( item ); - item->ViewRelease(); - ratsnest->Remove( item ); + commit.Remove( item ); gen_rastnest = true; } else @@ -160,13 +155,9 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete() { nextitem = item->Next(); - if( delAll || - ( item->Type() == PCB_LINE_T && masque_layer[item->GetLayer()] ) ) + if( delAll || ( item->Type() == PCB_LINE_T && masque_layer[item->GetLayer()] ) ) { - itemPicker.SetItem( item ); - pickersList.PushItem( itemPicker ); - item->ViewRelease(); - item->UnLink(); + commit.Remove( item ); } } } @@ -179,13 +170,9 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete() { nextitem = item->Next(); - if( delAll || - ( item->Type() == PCB_TEXT_T && del_text_layers[item->GetLayer()] ) ) + if( delAll || ( item->Type() == PCB_TEXT_T && del_text_layers[item->GetLayer()] ) ) { - itemPicker.SetItem( item ); - pickersList.PushItem( itemPicker ); - item->ViewRelease(); - item->UnLink(); + commit.Remove( item ); } } } @@ -205,13 +192,7 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete() if( del_fp ) { - itemPicker.SetItem( item ); - pickersList.PushItem( itemPicker ); - static_cast( item )->RunOnChildren( - std::bind( &KIGFX::VIEW_ITEM::ViewRelease, _1 ) ); - ratsnest->Remove( item ); - item->ViewRelease(); - item->UnLink(); + commit.Remove( item ); gen_rastnest = true; } } @@ -249,17 +230,12 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete() continue; } - itemPicker.SetItem( track ); - pickersList.PushItem( itemPicker ); - track->ViewRelease(); - ratsnest->Remove( track ); - track->UnLink(); + commit.Remove( track ); gen_rastnest = true; } } - if( pickersList.GetCount() ) - m_Parent->SaveCopyInUndoList( pickersList, UR_DELETED ); + commit.Push( wxT( "Global delete" ) ); if( m_DelMarkers->GetValue() ) pcb->DeleteMARKERs(); @@ -268,9 +244,7 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete() m_Parent->Compile_Ratsnest( NULL, true ); // There is a chance that some of tracks have changed their nets, so rebuild ratsnest from scratch - if( m_Parent->IsGalCanvasActive() ) - pcb->GetRatsnest()->ProcessBoard(); - - m_Parent->GetCanvas()->Refresh(); - m_Parent->OnModify(); + // TODO necessary? if not, remove rn_data.h header as well + //if( m_Parent->IsGalCanvasActive() ) + //pcb->GetRatsnest()->ProcessBoard(); } diff --git a/pcbnew/dialogs/dialog_global_modules_fields_edition.cpp b/pcbnew/dialogs/dialog_global_modules_fields_edition.cpp index 355d8a5ef5..25fdc9280c 100644 --- a/pcbnew/dialogs/dialog_global_modules_fields_edition.cpp +++ b/pcbnew/dialogs/dialog_global_modules_fields_edition.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -134,35 +135,21 @@ void DIALOG_GLOBAL_MODULES_FIELDS_EDITION::OnOKClick( wxCommandEvent& event ) void PCB_EDIT_FRAME::OnResetModuleTextSizes( wxCommandEvent& event ) { - DIALOG_GLOBAL_MODULES_FIELDS_EDITION dlg(this); + DIALOG_GLOBAL_MODULES_FIELDS_EDITION dlg( this ); dlg.ShowModal(); - - if( IsGalCanvasActive() ) - { - for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() ) - { - module->Value().ViewUpdate(); - module->Reference().ViewUpdate(); - } - } - - m_canvas->Refresh(); } void PCB_BASE_FRAME::ResetModuleTextSizes( const wxString & aFilter, bool aRef, bool aValue, bool aOthers ) { - MODULE* module; - BOARD_ITEM* boardItem; - ITEM_PICKER itemWrapper( NULL, UR_CHANGED ); - PICKED_ITEMS_LIST undoItemList; - unsigned int ii; + BOARD_COMMIT commit( this ); + + int modTextWidth = GetDesignSettings().m_ModuleTextWidth; + const wxSize& modTextSize = GetDesignSettings().m_ModuleTextSize; // Prepare undo list - for( module = GetBoard()->m_Modules; module; module = module->Next() ) + for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() ) { - itemWrapper.SetItem( module ); - if( ! aFilter.IsEmpty() ) { if( ! WildCompareString( aFilter, FROM_UTF8( module->GetFPID().Format().c_str() ), @@ -173,81 +160,50 @@ void PCB_BASE_FRAME::ResetModuleTextSizes( const wxString & aFilter, bool aRef, if( aRef ) { - TEXTE_MODULE *item = &module->Reference(); + TEXTE_MODULE* item = &module->Reference(); if( item->GetSize() != GetDesignSettings().m_ModuleTextSize || item->GetThickness() != GetDesignSettings().m_ModuleTextWidth ) { - undoItemList.PushItem( itemWrapper ); + commit.Modify( item ); + item->SetThickness( modTextWidth ); + item->SetSize( modTextSize ); } } if( aValue ) { - TEXTE_MODULE *item = &module->Value(); + TEXTE_MODULE* item = &module->Value(); if( item->GetSize() != GetDesignSettings().m_ModuleTextSize || item->GetThickness() != GetDesignSettings().m_ModuleTextWidth ) { - undoItemList.PushItem( itemWrapper ); + commit.Modify( item ); + item->SetThickness( modTextWidth ); + item->SetSize( modTextSize ); } } if( aOthers ) { // Go through all other module text fields - for( boardItem = module->GraphicalItems(); boardItem; boardItem = boardItem->Next() ) + for( BOARD_ITEM* boardItem = module->GraphicalItems(); boardItem; boardItem = boardItem->Next() ) { if( boardItem->Type() == PCB_MODULE_TEXT_T ) { - TEXTE_MODULE *item = static_cast( boardItem ); + TEXTE_MODULE* item = static_cast( boardItem ); if( item->GetSize() != GetDesignSettings().m_ModuleTextSize || item->GetThickness() != GetDesignSettings().m_ModuleTextWidth ) { - undoItemList.PushItem( itemWrapper ); + commit.Modify( item ); + item->SetThickness( modTextWidth ); + item->SetSize( modTextSize ); } } } } } - // Exit if there's nothing to do - if( !undoItemList.GetCount() ) - return; - - SaveCopyInUndoList( undoItemList, UR_CHANGED ); - - // Apply changes to modules in the undo list - for( ii = 0; ii < undoItemList.GetCount(); ii++ ) - { - module = (MODULE*) undoItemList.GetPickedItem( ii ); - - if( aRef ) - { - module->Reference().SetThickness( GetDesignSettings().m_ModuleTextWidth ); - module->Reference().SetSize( GetDesignSettings().m_ModuleTextSize ); - } - - if( aValue ) - { - module->Value().SetThickness( GetDesignSettings().m_ModuleTextWidth ); - module->Value().SetSize( GetDesignSettings().m_ModuleTextSize ); - } - - if( aOthers ) - { - for( boardItem = module->GraphicalItems(); boardItem; boardItem = boardItem->Next() ) - { - if( boardItem->Type() == PCB_MODULE_TEXT_T ) - { - TEXTE_MODULE *item = static_cast( boardItem ); - item->SetThickness( GetDesignSettings().m_ModuleTextWidth ); - item->SetSize( GetDesignSettings().m_ModuleTextSize ); - } - } - } - } - - OnModify(); + commit.Push( wxT( "Reset module text size" ) ); } diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index 5a53fa1faf..a6d2761e35 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -451,7 +452,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) // the new module replace the old module (pos, orient, ref, value // and connexions are kept) // and the source_module (old module) is deleted - PICKED_ITEMS_LIST pickList; + BOARD_COMMIT commit( pcbframe ); if( pcbframe->IsGalCanvasActive() ) { @@ -461,11 +462,10 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) view->Remove( source_module ); } - pcbframe->Exchange_Module( source_module, newmodule, &pickList ); + pcbframe->Exchange_Module( source_module, newmodule, commit ); newmodule->SetTimeStamp( module_in_edit->GetLink() ); - if( pickList.GetCount() ) - pcbframe->SaveCopyInUndoList( pickList, UR_UNSPECIFIED ); + commit.Push( wxT( "" ) ); } else // This is an insert command { diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index ef1288ee11..18021476ed 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -375,7 +375,7 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) STATUS_FLAGS flags = item->GetFlags(); item->ClearFlags(); - // Do not handle undo buffer, it is done by the properties dialogs + // Do not handle undo buffer, it is done by the properties dialogs @todo LEGACY // Display properties dialog provided by the legacy canvas frame editFrame->OnEditItemRequest( NULL, item ); diff --git a/pcbnew/xchgmod.cpp b/pcbnew/xchgmod.cpp index 649e66d882..87f98343e9 100644 --- a/pcbnew/xchgmod.cpp +++ b/pcbnew/xchgmod.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -76,7 +77,7 @@ private: const FPID& aNewFootprintFPID, bool eShowError ); - PICKED_ITEMS_LIST m_undoPickList; + BOARD_COMMIT m_commit; }; @@ -84,7 +85,7 @@ int DIALOG_EXCHANGE_MODULE::m_selectionMode = 0; DIALOG_EXCHANGE_MODULE::DIALOG_EXCHANGE_MODULE( PCB_EDIT_FRAME* parent, MODULE* Module ) : - DIALOG_EXCHANGE_MODULE_BASE( parent ) + DIALOG_EXCHANGE_MODULE_BASE( parent ), m_commit( parent ) { m_parent = parent; m_currentModule = Module; @@ -141,7 +142,6 @@ void DIALOG_EXCHANGE_MODULE::init() void DIALOG_EXCHANGE_MODULE::OnOkClick( wxCommandEvent& event ) { - m_undoPickList.ClearItemsList(); m_selectionMode = m_Selection->GetSelection(); bool result = false; @@ -172,8 +172,7 @@ void DIALOG_EXCHANGE_MODULE::OnOkClick( wxCommandEvent& event ) m_parent->GetCanvas()->Refresh(); } - if( m_undoPickList.GetCount() ) - m_parent->SaveCopyInUndoList( m_undoPickList, UR_UNSPECIFIED ); + m_commit.Push( wxT( "Changed footprint" ) ); } @@ -341,7 +340,7 @@ bool DIALOG_EXCHANGE_MODULE::change_1_Module( MODULE* aModule, const FPID& aNewFootprintFPID, bool aShowError ) { - MODULE* newModule; + MODULE* newModule; wxString line; if( aModule == NULL ) @@ -367,8 +366,7 @@ bool DIALOG_EXCHANGE_MODULE::change_1_Module( MODULE* aModule, return false; } - m_parent->Exchange_Module( aModule, newModule, &m_undoPickList ); - m_parent->GetBoard()->Add( newModule, ADD_APPEND ); + m_parent->Exchange_Module( aModule, newModule, m_commit ); if( aModule == m_currentModule ) m_currentModule = newModule; @@ -379,15 +377,14 @@ bool DIALOG_EXCHANGE_MODULE::change_1_Module( MODULE* aModule, } -void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule, - MODULE* aNewModule, - PICKED_ITEMS_LIST* aUndoPickList ) +void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule, + MODULE* aNewModule, + BOARD_COMMIT& aCommit ) { aNewModule->SetParent( GetBoard() ); /* place module without ratsnest refresh: this will be made later - * when all modules are on board - */ + * when all modules are on board */ PlaceModule( aNewModule, NULL, true ); // Copy full placement and pad net names (when possible) @@ -402,23 +399,12 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule, aNewModule->SetTimeStamp( aOldModule->GetTimeStamp() ); aNewModule->SetPath( aOldModule->GetPath() ); - if( aUndoPickList ) - { - GetBoard()->Remove( aOldModule ); - ITEM_PICKER picker_old( aOldModule, UR_DELETED ); - ITEM_PICKER picker_new( aNewModule, UR_NEW ); - aUndoPickList->PushItem( picker_old ); - aUndoPickList->PushItem( picker_new ); - } - else - { - GetGalCanvas()->GetView()->Remove( aOldModule ); - aOldModule->DeleteStructure(); - } + aCommit.Remove( aOldModule ); + aCommit.Add( aNewModule ); + // @todo LEGACY should be unnecessary GetBoard()->m_Status_Pcb = 0; aNewModule->ClearFlags(); - OnModify(); } From 65b12252315cbad6d1a7560222c3698fc7ee4c78 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 18 Aug 2016 16:28:04 +0200 Subject: [PATCH 44/61] Added CHT_DONE flag to COMMIT::Stage to skip add/remove step --- common/commit.cpp | 20 ++++++++++-------- include/commit.h | 45 ++++++++++++++++++++++++++++++++++------- pcbnew/board_commit.cpp | 34 ++++++++++++++++++++++--------- 3 files changed, 75 insertions(+), 24 deletions(-) diff --git a/common/commit.cpp b/common/commit.cpp index 22c053e43b..f398ad6399 100644 --- a/common/commit.cpp +++ b/common/commit.cpp @@ -42,15 +42,19 @@ COMMIT::~COMMIT() COMMIT& COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ) { - switch( aChangeType ) + assert( aChangeType != ( CHT_MODIFY | CHT_DONE ) ); // CHT_MODIFY and CHT_DONE are not compatible + + int flag = aChangeType & CHT_FLAGS; + + switch( aChangeType & CHT_TYPE ) { case CHT_ADD: assert( m_changedItems.find( aItem ) == m_changedItems.end() ); - makeEntry( aItem, CHT_ADD ); + makeEntry( aItem, CHT_ADD | flag ); return *this; case CHT_REMOVE: - makeEntry( aItem, CHT_REMOVE ); + makeEntry( aItem, CHT_REMOVE | flag ); return *this; case CHT_MODIFY: @@ -58,9 +62,9 @@ COMMIT& COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ) EDA_ITEM* parent = parentObject( aItem ); if( m_changedItems.find( parent ) != m_changedItems.end() ) - return *this; // item already modifed once + return *this; // item has been already modified once - makeEntry( parent, CHT_MODIFY, parent->Clone() ); + makeEntry( parent, CHT_MODIFY | flag, parent->Clone() ); return *this; } @@ -78,7 +82,7 @@ COMMIT& COMMIT::Stage( EDA_ITEM* aItem, EDA_ITEM* aCopy ) EDA_ITEM* parent = parentObject( aItem ); if( m_changedItems.find( parent ) != m_changedItems.end() ) - return *this; // item already modifed once + return *this; // item has been already modified once makeEntry( parent, CHT_MODIFY, aCopy ); @@ -131,7 +135,7 @@ COMMIT& COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO_T aModFlag ) void COMMIT::makeEntry( EDA_ITEM* aItem, CHANGE_TYPE aType, EDA_ITEM* aCopy ) { // Expect an item copy if it is going to be modified - assert( !!aCopy == ( aType == CHT_MODIFY ) ); + assert( !!aCopy == ( ( aType & CHT_TYPE ) == CHT_MODIFY ) ); COMMIT_LINE ent; @@ -144,7 +148,7 @@ void COMMIT::makeEntry( EDA_ITEM* aItem, CHANGE_TYPE aType, EDA_ITEM* aCopy ) } -COMMIT::CHANGE_TYPE COMMIT::convert( UNDO_REDO_T aType ) const +CHANGE_TYPE COMMIT::convert( UNDO_REDO_T aType ) const { switch( aType ) { diff --git a/include/commit.h b/include/commit.h index a036dda30b..3741536f68 100644 --- a/include/commit.h +++ b/include/commit.h @@ -32,6 +32,32 @@ class EDA_ITEM; +///> Types of changes +enum CHANGE_TYPE { + CHT_ADD = 1, + CHT_REMOVE = 2, + CHT_MODIFY = 4, + CHT_TYPE = CHT_ADD | CHT_REMOVE | CHT_MODIFY, + + ///> Flag to indicate the change is already applied, + ///> just notify observers (not compatible with CHT_MODIFY) + CHT_DONE = 8, + CHT_FLAGS = CHT_DONE +}; + +template +CHANGE_TYPE operator|( CHANGE_TYPE aTypeA, T aTypeB ) +{ + return CHANGE_TYPE( (int) aTypeA | (int) aTypeB ); +} + +template +CHANGE_TYPE operator&( CHANGE_TYPE aTypeA, T aTypeB ) +{ + return CHANGE_TYPE( (int) aTypeA & (int) aTypeB ); +} + + /** * Class COMMIT * @@ -44,13 +70,6 @@ class EDA_ITEM; class COMMIT { public: - ///> types of changes. - enum CHANGE_TYPE { - CHT_ADD = 0, - CHT_REMOVE = 1, - CHT_MODIFY = 2 - }; - COMMIT(); virtual ~COMMIT(); @@ -60,12 +79,24 @@ public: return Stage( aItem, CHT_ADD ); } + ///> Notifies observers that aItem has been added + COMMIT& Added( EDA_ITEM* aItem ) + { + return Stage( aItem, CHT_ADD | CHT_DONE ); + } + ///> Removes a new item from the model COMMIT& Remove( EDA_ITEM* aItem ) { return Stage( aItem, CHT_REMOVE ); } + ///> Notifies observers that aItem has been removed + COMMIT& Removed( EDA_ITEM* aItem ) + { + return Stage( aItem, CHT_REMOVE | CHT_DONE ); + } + ///> Modifies a given item in the model. ///> Must be called before modification is performed. COMMIT& Modify( EDA_ITEM* aItem ) diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index d2fcfc050b..62139f711e 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -68,6 +68,8 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) for( COMMIT_LINE& ent : m_changes ) { + int changeType = ent.m_type & CHT_TYPE; + int changeFlags = ent.m_type & CHT_FLAGS; BOARD_ITEM* boardItem = static_cast( ent.m_item ); // Module items need to be saved in the undo buffer before modification @@ -82,7 +84,7 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) { if( !ent.m_copy ) { - assert( ent.m_type != CHT_MODIFY ); // too late to make a copy.. + assert( changeType != CHT_MODIFY ); // too late to make a copy.. ent.m_copy = ent.m_item->Clone(); } @@ -99,14 +101,17 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) } } - switch( ent.m_type ) + switch( changeType ) { case CHT_ADD: { if( !m_editModules ) { undoList.PushItem( ITEM_PICKER( boardItem, UR_NEW ) ); - board->Add( boardItem ); + + if( !( changeFlags & CHT_DONE ) ) + board->Add( boardItem ); + //ratsnest->Add( boardItem ); // TODO currently done by BOARD::Add() if( boardItem->Type() == PCB_MODULE_T ) @@ -117,8 +122,11 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) } else { + // modules inside modules are not supported yet assert( boardItem->Type() != PCB_MODULE_T ); - board->m_Modules->Add( boardItem ); + + if( !( changeFlags & CHT_DONE ) ) + board->m_Modules->Add( boardItem ); } view->Add( boardItem ); @@ -174,9 +182,12 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) { view->Remove( boardItem ); - MODULE* module = static_cast( boardItem->GetParent() ); - assert( module && module->Type() == PCB_MODULE_T ); - module->Delete( boardItem ); + if( !( changeFlags & CHT_DONE ) ) + { + MODULE* module = static_cast( boardItem->GetParent() ); + assert( module && module->Type() == PCB_MODULE_T ); + module->Delete( boardItem ); + } board->m_Status_Pcb = 0; // it is done in the legacy view (ratsnest perhaps?) } @@ -195,7 +206,10 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) case PCB_ZONE_T: // SEG_ZONE items are now deprecated case PCB_ZONE_AREA_T: view->Remove( boardItem ); - board->Remove( boardItem ); + + if( !( changeFlags & CHT_DONE ) ) + board->Remove( boardItem ); + //ratsnest->Remove( boardItem ); // currently done by BOARD::Remove() break; @@ -209,7 +223,9 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) module->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) ); view->Remove( module ); - board->Remove( module ); + + if( !( changeFlags & CHT_DONE ) ) + board->Remove( module ); // Clear flags to indicate, that the ratsnest, list of nets & pads are not valid anymore board->m_Status_Pcb = 0; From edf64afa3e951a0bfe01c5457c54541b0315dc34 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 19 Aug 2016 14:03:49 +0200 Subject: [PATCH 45/61] Fixed freezes after appending a board. --- pcbnew/tools/pcbnew_control.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 32f72a89a2..ecc7e4fd79 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -838,7 +838,7 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent ) continue; } - commit.Add( track ); + commit.Added( track ); m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, track ); } @@ -846,7 +846,7 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent ) for( ; module; module = module->Next() ) { - commit.Add( module ); + commit.Added( module ); m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, module ); } @@ -854,7 +854,7 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent ) for( ; drawing; drawing = drawing->Next() ) { - commit.Add( drawing ); + commit.Added( drawing ); m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, drawing ); } @@ -862,7 +862,7 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent ) zone = board->GetArea( zonescount ) ) { ++zonescount; - commit.Add( zone ); + commit.Added( zone ); m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, zone ); } @@ -890,7 +890,7 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent ) // Ratsnest board->BuildListOfNets(); board->SynchronizeNetsAndNetClasses(); - board->GetRatsnest()->Recalculate(); + board->GetRatsnest()->ProcessBoard(); // Start dragging the appended board SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); From b0b64ac9647a4a9eed671f9f16cf4ebdf2d5d0df Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 2 Sep 2016 09:03:49 +0200 Subject: [PATCH 46/61] Fixed freeze after updating a footprint using the FP editor. --- pcbnew/modedit.cpp | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index a6d2761e35..de8191cde3 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -437,65 +437,41 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) } m_toolManager->RunAction( COMMON_ACTIONS::selectionClear, true ); + BOARD_COMMIT commit( pcbframe ); // Create the "new" module MODULE* newmodule = new MODULE( *module_in_edit ); newmodule->SetParent( mainpcb ); newmodule->SetLink( 0 ); - // Put the footprint in the main pcb linked list. - mainpcb->Add( newmodule ); - if( source_module ) // this is an update command { // In the main board, // the new module replace the old module (pos, orient, ref, value // and connexions are kept) // and the source_module (old module) is deleted - BOARD_COMMIT commit( pcbframe ); - - if( pcbframe->IsGalCanvasActive() ) - { - KIGFX::VIEW* view = pcbframe->GetGalCanvas()->GetView(); - source_module->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, - std::placeholders::_1 ) ); - view->Remove( source_module ); - } - pcbframe->Exchange_Module( source_module, newmodule, commit ); newmodule->SetTimeStamp( module_in_edit->GetLink() ); - - commit.Push( wxT( "" ) ); + commit.Push( wxT( "Update module" ) ); } else // This is an insert command { wxPoint cursor_pos = pcbframe->GetCrossHairPosition(); + commit.Add( newmodule ); pcbframe->SetCrossHairPosition( wxPoint( 0, 0 ) ); pcbframe->PlaceModule( newmodule, NULL ); newmodule->SetPosition( wxPoint( 0, 0 ) ); pcbframe->SetCrossHairPosition( cursor_pos ); newmodule->SetTimeStamp( GetNewTimeStamp() ); - pcbframe->SaveCopyInUndoList( newmodule, UR_NEW ); + commit.Push( wxT( "Insert module" ) ); } newmodule->ClearFlags(); GetScreen()->ClrModify(); pcbframe->SetCurItem( NULL ); + // @todo LEGACY should be unnecessary mainpcb->m_Status_Pcb = 0; - - if( pcbframe->IsGalCanvasActive() ) - { - RN_DATA* ratsnest = pcbframe->GetBoard()->GetRatsnest(); - ratsnest->Update( newmodule ); - ratsnest->Recalculate(); - - KIGFX::VIEW* view = pcbframe->GetGalCanvas()->GetView(); - newmodule->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, - std::placeholders::_1 ) ); - view->Add( newmodule ); - pcbframe->GetGalCanvas()->ForceRefresh(); - } } break; From 029e275aa0f1cc13286b5d24b7543b4646420af8 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 2 Sep 2016 14:24:43 +0200 Subject: [PATCH 47/61] Unselect modified component before replacing by the FP editor. --- pcbnew/modedit.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index de8191cde3..c4db2911f8 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -437,6 +437,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) } m_toolManager->RunAction( COMMON_ACTIONS::selectionClear, true ); + pcbframe->GetToolManager()->RunAction( COMMON_ACTIONS::selectionClear, true ); BOARD_COMMIT commit( pcbframe ); // Create the "new" module From 267f01fa69951e96402cb82b8c88aed2e843070c Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 2 Sep 2016 15:53:51 +0200 Subject: [PATCH 48/61] Code formatting (BOARD_NETLIST_UPDATER) --- pcbnew/board_netlist_updater.cpp | 118 +++++++++++------------ pcbnew/board_netlist_updater.h | 139 +++++++++++++-------------- pcbnew/dialogs/dialog_update_pcb.cpp | 29 +++--- 3 files changed, 141 insertions(+), 145 deletions(-) diff --git a/pcbnew/board_netlist_updater.cpp b/pcbnew/board_netlist_updater.cpp index f0a628b0ba..d0dc086986 100644 --- a/pcbnew/board_netlist_updater.cpp +++ b/pcbnew/board_netlist_updater.cpp @@ -49,35 +49,37 @@ #include -BOARD_NETLIST_UPDATER::BOARD_NETLIST_UPDATER ( PCB_EDIT_FRAME *aFrame, BOARD *aBoard ) : - m_frame ( aFrame ), +BOARD_NETLIST_UPDATER::BOARD_NETLIST_UPDATER( PCB_EDIT_FRAME* aFrame, BOARD* aBoard ) : + m_frame( aFrame ), m_board( aBoard ) { m_reporter = &NULL_REPORTER::GetInstance(); m_undoList = new PICKED_ITEMS_LIST; - m_deleteSinglePadNets = true; - m_deleteUnusedComponents = false; - m_isDryRun = false; - m_replaceFootprints = true; - m_lookupByTimestamp = false; + m_deleteSinglePadNets = true; + m_deleteUnusedComponents = false; + m_isDryRun = false; + m_replaceFootprints = true; + m_lookupByTimestamp = false; - m_warningCount = 0; - m_errorCount = 0; + m_warningCount = 0; + m_errorCount = 0; } -BOARD_NETLIST_UPDATER::~BOARD_NETLIST_UPDATER () + +BOARD_NETLIST_UPDATER::~BOARD_NETLIST_UPDATER() { delete m_undoList; } + void BOARD_NETLIST_UPDATER::pushUndo( BOARD_ITEM* aItem, UNDO_REDO_T aCommandType, BOARD_ITEM* aCopy ) { ITEM_PICKER picker( aItem, aCommandType ); if( aCommandType == UR_CHANGED ) { - if( m_undoList->FindItem ( aItem ) >= 0 ) // add only once + if( m_undoList->FindItem( aItem ) >= 0 ) // add only once return; picker.SetLink( aCopy ? aCopy : aItem->Clone() ); @@ -86,6 +88,7 @@ void BOARD_NETLIST_UPDATER::pushUndo( BOARD_ITEM* aItem, UNDO_REDO_T aCommandTyp m_undoList->PushItem( picker ); } + wxPoint BOARD_NETLIST_UPDATER::estimateComponentInsertionPosition() { wxPoint bestPosition; @@ -124,20 +127,18 @@ MODULE* BOARD_NETLIST_UPDATER::addNewComponent( COMPONENT* aComponent ) GetChars( aComponent->GetReference() ), GetChars( aComponent->GetTimeStamp() ), GetChars( aComponent->GetFPID().Format() ) ); - m_reporter->Report( msg, REPORTER::RPT_INFO ); msg.Printf( _( "Add component %s, footprint: %s.\n" ), GetChars( aComponent->GetReference() ), GetChars( aComponent->GetFPID().Format() ) ); - m_reporter->Report( msg, REPORTER::RPT_ACTION ); if( !m_isDryRun ) { // Owned by NETLIST, can only copy it. - MODULE *footprint = new MODULE( *aComponent->GetModule() ); + MODULE* footprint = new MODULE( *aComponent->GetModule() ); footprint->SetParent( m_board ); footprint->SetPosition( estimateComponentInsertionPosition( ) ); footprint->SetTimeStamp( GetNewTimeStamp() ); @@ -165,23 +166,22 @@ MODULE* BOARD_NETLIST_UPDATER::addNewComponent( COMPONENT* aComponent ) GetChars( aComponent->GetFPID().Format() ) ); m_reporter->Report( msg, REPORTER::RPT_INFO ); - - m_errorCount ++; + ++m_errorCount; } return NULL; } -MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE *aPcbComponent, COMPONENT* aNewComponent ) + +MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE* aPcbComponent, COMPONENT* aNewComponent ) { wxString msg; if( !m_replaceFootprints ) return NULL; -// Test if the footprint has not changed - if( aNewComponent->GetFPID().empty() || - aPcbComponent->GetFPID() == aNewComponent->GetFPID() ) + // Test if the footprint has not changed + if( aNewComponent->GetFPID().empty() || aPcbComponent->GetFPID() == aNewComponent->GetFPID() ) return NULL; if( aNewComponent->GetModule() != NULL ) @@ -221,8 +221,9 @@ MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE *aPcb return newFootprint; } - } else { - + } + else + { msg.Printf( _( "Cannot change component %s footprint due to missing " "footprint %s.\n" ), GetChars( aPcbComponent->GetReference() ), @@ -238,13 +239,14 @@ MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE *aPcb m_reporter->Report( msg, REPORTER::RPT_INFO ); - m_errorCount ++; + ++m_errorCount; } return NULL; } -bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE *aPcbComponent, COMPONENT* aNewComponent ) + +bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE* aPcbComponent, COMPONENT* aNewComponent ) { wxString msg; @@ -292,9 +294,10 @@ bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE *aPcbComponent, CO GetChars( aPcbComponent->GetPath() ), GetChars( aPcbComponent->GetValue() ), GetChars( aNewComponent->GetValue() ) ); + m_reporter->Report( msg, REPORTER::RPT_ACTION ); - if ( !m_isDryRun ) + if( !m_isDryRun ) { changed = true; aPcbComponent->SetValue( aNewComponent->GetValue() ); @@ -308,6 +311,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE *aPcbComponent, CO GetChars( aPcbComponent->GetReference() ), GetChars( aPcbComponent->GetPath() ), GetChars( aNewComponent->GetTimeStamp() ) ); + m_reporter->Report( msg, REPORTER::RPT_INFO ); if ( !m_isDryRun ) @@ -325,7 +329,8 @@ bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE *aPcbComponent, CO return true; } -bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE *aPcbComponent, COMPONENT* aNewComponent ) + +bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent, COMPONENT* aNewComponent ) { wxString msg; @@ -333,7 +338,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE *aPcbComponent MODULE* copy = (MODULE*) aPcbComponent->Clone(); // At this point, the component footprint is updated. Now update the nets. - for( D_PAD *pad = aPcbComponent->Pads(); pad; pad = pad->Next() ) + for( D_PAD* pad = aPcbComponent->Pads(); pad; pad = pad->Next() ) { COMPONENT_NET net = aNewComponent->GetNet( pad->GetPadName() ); @@ -351,7 +356,6 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE *aPcbComponent GetChars( aPcbComponent->GetPath() ), GetChars( pad->GetPadName() ) ); m_reporter->Report( msg, REPORTER::RPT_INFO ); - } if( !m_isDryRun ) @@ -377,13 +381,12 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE *aPcbComponent pushUndo( netinfo, UR_NEW ); } - msg.Printf( _( "Add net %s.\n" ), - GetChars( net.GetNetName() ) ); + msg.Printf( _( "Add net %s.\n" ), GetChars( net.GetNetName() ) ); m_reporter->Report( msg, REPORTER::RPT_ACTION ); } - if( pad->GetNetname() != wxString("") ) + if( !pad->GetNetname().IsEmpty() ) { msg.Printf( _( "Reconnect component %s pin %s from net %s to net %s.\n"), GetChars( aPcbComponent->GetReference() ), @@ -410,7 +413,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE *aPcbComponent m_reporter->Report( msg, REPORTER::RPT_INFO ); - if ( !m_isDryRun ) + if( !m_isDryRun ) { changed = true; pad->SetNetCode( netinfo->GetNet() ); @@ -427,6 +430,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE *aPcbComponent return true; } + bool BOARD_NETLIST_UPDATER::deleteUnusedComponents( NETLIST& aNetlist ) { wxString msg; @@ -467,6 +471,7 @@ bool BOARD_NETLIST_UPDATER::deleteUnusedComponents( NETLIST& aNetlist ) return true; } + bool BOARD_NETLIST_UPDATER::deleteSinglePadNets() { int count = 0; @@ -520,7 +525,6 @@ bool BOARD_NETLIST_UPDATER::deleteSinglePadNets() { msg.Printf( _( "Remove single pad net %s." ), GetChars( previouspad->GetNetname() ) ); - m_reporter->Report( msg, REPORTER::RPT_ACTION ); msg.Printf( _( "Remove single pad net \"%s\" on \"%s\" pad '%s'\n" ), @@ -554,6 +558,7 @@ bool BOARD_NETLIST_UPDATER::deleteSinglePadNets() return true; } + bool BOARD_NETLIST_UPDATER::testConnectivity( NETLIST& aNetlist ) { // Last step: Some tests: @@ -592,7 +597,7 @@ bool BOARD_NETLIST_UPDATER::testConnectivity( NETLIST& aNetlist ) GetChars( padname ), GetChars( footprint->GetFPID().Format() ) ); m_reporter->Report( msg, REPORTER::RPT_ERROR ); - m_errorCount ++; + ++m_errorCount; } } @@ -611,13 +616,14 @@ bool BOARD_NETLIST_UPDATER::testConnectivity( NETLIST& aNetlist ) msg.Printf( _( "Copper zone (net name %s): net has no pads connected." ), GetChars( zone->GetNet()->GetNetname() ) ); m_reporter->Report( msg, REPORTER::RPT_WARNING ); - m_warningCount ++; + ++m_warningCount; } } return true; } + bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist ) { wxString msg; @@ -630,17 +636,15 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist ) m_board->SetStatus( 0 ); } - for( int i = 0; i < (int) aNetlist.GetCount(); i++ ) { COMPONENT* component = aNetlist.GetComponent( i ); - MODULE *footprint = NULL; + MODULE* footprint = NULL; msg.Printf( _( "Processing component \"%s:%s:%s\".\n" ), GetChars( component->GetReference() ), GetChars( component->GetTimeStamp() ), GetChars( component->GetFPID().Format() ) ); - m_reporter->Report( msg, REPORTER::RPT_INFO ); if( aNetlist.IsFindByTimeStamp() ) @@ -650,8 +654,9 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist ) if( footprint ) // An existing footprint. { - MODULE *newFootprint = replaceComponent ( aNetlist, footprint, component ); - if ( newFootprint ) + MODULE* newFootprint = replaceComponent( aNetlist, footprint, component ); + + if( newFootprint ) footprint = newFootprint; } else @@ -666,9 +671,6 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist ) } } - - - //aNetlist.GetDeleteExtraFootprints() if( m_deleteUnusedComponents ) @@ -679,7 +681,7 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist ) if ( !m_isDryRun ) { - m_frame->SaveCopyInUndoList( *m_undoList, UR_UNSPECIFIED, wxPoint(0, 0) ); + m_frame->SaveCopyInUndoList( *m_undoList, UR_UNSPECIFIED, wxPoint( 0, 0 ) ); m_frame->OnModify(); m_frame->Compile_Ratsnest( NULL, true ); @@ -689,35 +691,31 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist ) } // Update the ratsnest + m_reporter->Report( wxT( "" ), REPORTER::RPT_ACTION ); + m_reporter->Report( wxT( "" ), REPORTER::RPT_ACTION ); - m_reporter->Report( wxT(""), REPORTER::RPT_ACTION ); - m_reporter->Report( wxT(""), REPORTER::RPT_ACTION ); - - msg.Printf( _( "Total warnings: %d, errors: %d." ), - m_warningCount, m_errorCount ); - + msg.Printf( _( "Total warnings: %d, errors: %d." ), m_warningCount, m_errorCount ); m_reporter->Report( msg, REPORTER::RPT_ACTION ); - - if ( m_errorCount ) + if( m_errorCount ) { - - m_reporter->Report( _("Errors occured during the netlist update. Unless you " - "fix them, your board will not be consistent with the schematics." ), + m_reporter->Report( _( "Errors occured during the netlist update. Unless you " + "fix them, your board will not be consistent with the schematics." ), REPORTER::RPT_ERROR ); return false; - } else { - m_reporter->Report( _("Netlist update successful!" ), - REPORTER::RPT_ACTION ); - + } + else + { + m_reporter->Report( _( "Netlist update successful!" ), REPORTER::RPT_ACTION ); } return true; } + bool BOARD_NETLIST_UPDATER::UpdateNetlist( const wxString& aNetlistFileName, - const wxString& aCmpFileName ) + const wxString& aCmpFileName ) { return false; } diff --git a/pcbnew/board_netlist_updater.h b/pcbnew/board_netlist_updater.h index efe50894b9..cf3cba506f 100644 --- a/pcbnew/board_netlist_updater.h +++ b/pcbnew/board_netlist_updater.h @@ -72,94 +72,91 @@ class PCB_EDIT_FRAME; class BOARD_NETLIST_UPDATER { public: + BOARD_NETLIST_UPDATER( PCB_EDIT_FRAME* aFrame, BOARD* aBoard ); + ~BOARD_NETLIST_UPDATER(); - BOARD_NETLIST_UPDATER( PCB_EDIT_FRAME *aFrame, BOARD *aBoard ); - ~BOARD_NETLIST_UPDATER(); + /** + * Function UpdateNetlist() + * + * Updates the board's components according to the new netlist. + * See BOARD_NETLIST_UPDATER class description for the details of the process. + * @param aNetlist the new netlist + * @return true if process was completed successfully + */ + bool UpdateNetlist( NETLIST& aNetlist ); - /** - * Function UpdateNetlist() - * - * Updates the board's components according to the new netlist. - * See BOARD_NETLIST_UPDATER class description for the details of the process. - * @param aNetlist the new netlist - * @return true if process was completed successfully - */ - bool UpdateNetlist( NETLIST& aNetlist ); + // @todo: implement and move NETLIST::ReadPcbNetlist here + bool UpdateNetlist( const wxString& aNetlistFileName, const wxString& aCmpFileName ); - // @todo: implement and move NETLIST::ReadPcbNetlist here - bool UpdateNetlist( const wxString& aNetlistFileName, - const wxString& aCmpFileName ); + ///> Sets the reporter object + void SetReporter( REPORTER* aReporter ) + { + m_reporter = aReporter; + } + ///> Enables "delete single pad nets" option + void SetDeleteSinglePadNets( bool aEnabled ) + { + m_deleteSinglePadNets = aEnabled; + } - ///> Sets the reporter object - void SetReporter ( REPORTER *aReporter ) - { - m_reporter = aReporter; - } + ///> Enables dry run mode (just report, no changes to PCB) + void SetIsDryRun( bool aEnabled ) + { + m_isDryRun = aEnabled; + } - ///> Enables "delete single pad nets" option - void SetDeleteSinglePadNets( bool aEnabled ) - { - m_deleteSinglePadNets = aEnabled; - } + ///> Enables replacing footprints with new ones + void SetReplaceFootprints( bool aEnabled ) + { + m_replaceFootprints = aEnabled; + } - ///> Enables dry run mode (just report, no changes to PCB) - void SetIsDryRun ( bool aEnabled ) - { - m_isDryRun = aEnabled; - } + ///> Enables removing unused components + void SetDeleteUnusedComponents( bool aEnabled ) + { + m_deleteUnusedComponents = aEnabled; + } - ///> Enables replacing footprints with new ones - void SetReplaceFootprints ( bool aEnabled ) - { - m_replaceFootprints = aEnabled; - } + ///> Enables component lookup by timestamp instead of reference + void SetLookupByTimestamp( bool aEnabled ) + { + m_lookupByTimestamp = aEnabled; + } - ///> Enables removing unused components - void SetDeleteUnusedComponents ( bool aEnabled ) - { - m_deleteUnusedComponents = aEnabled; - } - - ///> Enables component lookup by timestamp instead of reference - void SetLookupByTimestamp ( bool aEnabled ) - { - m_lookupByTimestamp = aEnabled; - } - - std::vector GetAddedComponents() const - { - return m_addedComponents; - } + std::vector GetAddedComponents() const + { + return m_addedComponents; + } private: - void pushUndo( BOARD_ITEM* aItem, UNDO_REDO_T aCommandType, BOARD_ITEM* aCopy = NULL ); + void pushUndo( BOARD_ITEM* aItem, UNDO_REDO_T aCommandType, BOARD_ITEM* aCopy = NULL ); - wxPoint estimateComponentInsertionPosition(); - MODULE* addNewComponent( COMPONENT* aComponent ); - MODULE* replaceComponent( NETLIST& aNetlist, MODULE *aPcbComponent, COMPONENT* aNewComponent ); - bool updateComponentParameters( MODULE *aPcbComponent, COMPONENT* aNewComponent ); - bool updateComponentPadConnections( MODULE *aPcbComponent, COMPONENT* aNewComponent ); - bool deleteUnusedComponents( NETLIST& aNetlist ); - bool deleteSinglePadNets(); - bool testConnectivity( NETLIST& aNetlist ); + wxPoint estimateComponentInsertionPosition(); + MODULE* addNewComponent( COMPONENT* aComponent ); + MODULE* replaceComponent( NETLIST& aNetlist, MODULE* aPcbComponent, COMPONENT* aNewComponent ); + bool updateComponentParameters( MODULE* aPcbComponent, COMPONENT* aNewComponent ); + bool updateComponentPadConnections( MODULE* aPcbComponent, COMPONENT* aNewComponent ); + bool deleteUnusedComponents( NETLIST& aNetlist ); + bool deleteSinglePadNets(); + bool testConnectivity( NETLIST& aNetlist ); - PICKED_ITEMS_LIST *m_undoList; - PCB_EDIT_FRAME *m_frame; - BOARD *m_board; - REPORTER *m_reporter; + PICKED_ITEMS_LIST* m_undoList; + PCB_EDIT_FRAME* m_frame; + BOARD* m_board; + REPORTER* m_reporter; - std::vector m_addedComponents; + std::vector m_addedComponents; - bool m_deleteSinglePadNets; - bool m_deleteUnusedComponents; - bool m_isDryRun; - bool m_replaceFootprints; - bool m_lookupByTimestamp; + bool m_deleteSinglePadNets; + bool m_deleteUnusedComponents; + bool m_isDryRun; + bool m_replaceFootprints; + bool m_lookupByTimestamp; - int m_warningCount; - int m_errorCount; + int m_warningCount; + int m_errorCount; }; #endif diff --git a/pcbnew/dialogs/dialog_update_pcb.cpp b/pcbnew/dialogs/dialog_update_pcb.cpp index 7efcda67b0..18f08a16f7 100644 --- a/pcbnew/dialogs/dialog_update_pcb.cpp +++ b/pcbnew/dialogs/dialog_update_pcb.cpp @@ -19,26 +19,27 @@ DIALOG_UPDATE_PCB::DIALOG_UPDATE_PCB( PCB_EDIT_FRAME* aParent, NETLIST *aNetlist m_netlist (aNetlist) { m_messagePanel->SetLabel( _("Changes to be applied:") ); - m_messagePanel->SetLazyUpdate ( true ); + m_messagePanel->SetLazyUpdate( true ); m_netlist->SortByReference(); m_btnPerformUpdate->SetFocus(); m_messagePanel->SetVisibleSeverities( REPORTER::RPT_WARNING | REPORTER::RPT_ERROR | REPORTER::RPT_ACTION ); } + DIALOG_UPDATE_PCB::~DIALOG_UPDATE_PCB() { - } + void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) { m_messagePanel->Clear(); REPORTER &reporter = m_messagePanel->Reporter(); KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); - TOOL_MANAGER *toolManager = m_frame->GetToolManager(); - BOARD *board = m_frame->GetBoard(); + TOOL_MANAGER* toolManager = m_frame->GetToolManager(); + BOARD* board = m_frame->GetBoard(); if( !aDryRun ) { @@ -57,7 +58,8 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) m_netlist->SetFindByTimeStamp( m_matchByTimestamp->GetValue() ); m_netlist->SetReplaceFootprints( true ); - try { + try + { m_frame->LoadFootprints( *m_netlist, &reporter ); } catch( IO_ERROR &error ) @@ -70,14 +72,12 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) } BOARD_NETLIST_UPDATER updater( m_frame, m_frame->GetBoard() ); - updater.SetReporter ( &reporter ); updater.SetIsDryRun( aDryRun); updater.SetLookupByTimestamp( m_matchByTimestamp->GetValue() ); updater.SetDeleteUnusedComponents ( true ); updater.SetReplaceFootprints( true ); - updater.SetDeleteSinglePadNets ( false ); - + updater.SetDeleteSinglePadNets( false ); updater.UpdateNetlist( *m_netlist ); m_messagePanel->Flush(); @@ -103,10 +103,8 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) board->GetRatsnest()->ProcessBoard(); m_frame->Compile_Ratsnest( NULL, true ); - m_frame->SetMsgPanel( board ); - if( m_frame->IsGalCanvasActive() ) { m_frame->SpreadFootprints( &newFootprints, false, false, m_frame->GetCrossHairPosition() ); @@ -117,30 +115,33 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) { toolManager->RunAction( COMMON_ACTIONS::selectItem, true, footprint ); } + toolManager->InvokeTool( "pcbnew.InteractiveEdit" ); } } - m_btnPerformUpdate->Enable( false ); m_btnPerformUpdate->SetLabel( _( "Update complete" ) ); - m_btnCancel->SetLabel ( _("Close") ); + m_btnCancel->SetLabel( _("Close") ); m_btnCancel->SetFocus(); } + void DIALOG_UPDATE_PCB::OnMatchChange( wxCommandEvent& event ) { PerformUpdate( true ); } + void DIALOG_UPDATE_PCB::OnCancelClick( wxCommandEvent& event ) { EndModal( wxID_CANCEL ); } + void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event ) { - m_messagePanel->SetLabel( _("Changes applied to the PCB:") ); + m_messagePanel->SetLabel( _( "Changes applied to the PCB:" ) ); PerformUpdate( false ); - m_btnCancel->SetFocus( ); + m_btnCancel->SetFocus(); } From 6481ff75c98569bdbb6a9de4df2571d38f9c83af Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 2 Sep 2016 16:38:40 +0200 Subject: [PATCH 49/61] Changed one of COMMIT::Stage() methods to COMMIT::Modified() --- common/commit.cpp | 5 +++-- include/commit.h | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/common/commit.cpp b/common/commit.cpp index f398ad6399..54b1278436 100644 --- a/common/commit.cpp +++ b/common/commit.cpp @@ -3,6 +3,7 @@ * * Copyright (C) 2016 CERN * @author Tomasz Wlostowski + * @author Maciej Suminski * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -77,7 +78,7 @@ COMMIT& COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ) } -COMMIT& COMMIT::Stage( EDA_ITEM* aItem, EDA_ITEM* aCopy ) +COMMIT& COMMIT::Modified( EDA_ITEM* aItem, EDA_ITEM* aCopy ) { EDA_ITEM* parent = parentObject( aItem ); @@ -120,7 +121,7 @@ COMMIT& COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO_T aModFlag ) assert( change_type == UR_CHANGED ); // There was already a copy created, so use it - Stage( item, copy ); + Modified( item, copy ); } else { diff --git a/include/commit.h b/include/commit.h index 3741536f68..646e991a4b 100644 --- a/include/commit.h +++ b/include/commit.h @@ -3,6 +3,7 @@ * * Copyright (C) 2016 CERN * @author Tomasz Wlostowski + * @author Maciej Suminski * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -104,12 +105,13 @@ public: return Stage( aItem, CHT_MODIFY ); } + ///> Creates an undo entry for an item that has been already modified. Requires a copy done + ///> before the modification. + COMMIT& Modified( EDA_ITEM* aItem, EDA_ITEM* aCopy ); + ///> Adds a change of the item aItem of type aChangeType to the change list. COMMIT& Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ); - ///> Adds a change of an item with its copy done before the change has occurred. - COMMIT& Stage( EDA_ITEM* aItem, EDA_ITEM* aCopy ); - COMMIT& Stage( std::vector& container, CHANGE_TYPE aChangeType ); COMMIT& Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO_T aModFlag = UR_UNSPECIFIED ); From 694aa7ff5ba13e58518b9d580f420cb3eb573b3a Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 5 Sep 2016 12:17:30 +0200 Subject: [PATCH 50/61] Handle pad autonumbering when the number set is empty. --- include/class_board_item.h | 2 +- pcbnew/class_board_item.cpp | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/class_board_item.h b/include/class_board_item.h index 77a26a7a16..af8491ce26 100644 --- a/include/class_board_item.h +++ b/include/class_board_item.h @@ -79,7 +79,7 @@ protected: LAYER_ID m_Layer; static int getTrailingInt( wxString aStr ); - static int getNextNumberInSequence( std::set aSeq, bool aFillSequenceGaps ); + static int getNextNumberInSequence( const std::set& aSeq, bool aFillSequenceGaps ); public: diff --git a/pcbnew/class_board_item.cpp b/pcbnew/class_board_item.cpp index 1ae6f8a856..c1e60dbbf9 100644 --- a/pcbnew/class_board_item.cpp +++ b/pcbnew/class_board_item.cpp @@ -219,8 +219,12 @@ int BOARD_ITEM::getTrailingInt( wxString aStr ) return number; } -int BOARD_ITEM::getNextNumberInSequence( std::set aSeq, bool aFillSequenceGaps) + +int BOARD_ITEM::getNextNumberInSequence( const std::set& aSeq, bool aFillSequenceGaps) { + if( aSeq.empty() ) + return 1; + // By default go to the end of the sequence int candidate = *aSeq.rbegin(); @@ -230,16 +234,16 @@ int BOARD_ITEM::getNextNumberInSequence( std::set aSeq, bool aFillSequenceG // start at the beginning candidate = *aSeq.begin(); - for( std::set::iterator it = aSeq.begin(), - itEnd = aSeq.end(); it != itEnd; ++it ) + for( auto it : aSeq ) { - if( *it - candidate > 1 ) + if( it - candidate > 1 ) break; - candidate = *it; + candidate = it; } } - candidate++; + ++candidate; + return candidate; } From 790b6eaeb9cf10f6e2b763c7913b727959181e0d Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 5 Sep 2016 12:18:26 +0200 Subject: [PATCH 51/61] Fixed ratsnest updates on undo/redo --- pcbnew/undo_redo.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pcbnew/undo_redo.cpp b/pcbnew/undo_redo.cpp index dd72f59416..d184bb204d 100644 --- a/pcbnew/undo_redo.cpp +++ b/pcbnew/undo_redo.cpp @@ -382,6 +382,7 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool bool build_item_list = true; // if true the list of existing items must be rebuilt + // Restore changes in reverse order for( int ii = aList->GetCount() - 1; ii >= 0 ; ii-- ) { item = (BOARD_ITEM*) aList->GetPickedItem( ii ); @@ -549,6 +550,19 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool // Rebuild pointers and ratsnest that can be changed. if( reBuild_ratsnest ) { + // Compile ratsnest propagates nets from pads to tracks + /// @todo LEGACY Compile_Ratsnest() has to be rewritten and moved to RN_DATA + Compile_Ratsnest( NULL, true ); + + if( GetModel()->Type() == PCB_T ) + { + /// @todo LEGACY Compile_Ratsnest() might have changed nets for tracks, + //so we need to refresh them + BOARD* board = static_cast( GetModel() ); + + for( TRACK* track = board->m_Track; track; track = track->Next() ) + track->ViewUpdate(); + } if( IsGalCanvasActive() ) { @@ -557,10 +571,6 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool else ratsnest->Recalculate(); } - else - { - Compile_Ratsnest( NULL, true ); - } } } From 828f28ecca21104a07c7332cbda88a94062471ef Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 5 Sep 2016 12:18:55 +0200 Subject: [PATCH 52/61] Ratsnest Add()/Remove()/Update() return true on success --- pcbnew/ratsnest_data.cpp | 70 +++++++++++++++++++++++++++++----------- pcbnew/ratsnest_data.h | 10 ++++-- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/pcbnew/ratsnest_data.cpp b/pcbnew/ratsnest_data.cpp index f69557a509..6fcf592214 100644 --- a/pcbnew/ratsnest_data.cpp +++ b/pcbnew/ratsnest_data.cpp @@ -1033,22 +1033,27 @@ void RN_NET::processPads() } -void RN_DATA::Add( const BOARD_ITEM* aItem ) +bool RN_DATA::Add( const BOARD_ITEM* aItem ) { int net; if( aItem->IsConnected() ) { net = static_cast( aItem )->GetNetCode(); - if( net < 1 ) // do not process unconnected items - return; + if( net < 1 ) // do not process unconnected items + return false; + + wxASSERT( (unsigned) net < m_nets.size() ); + /// @todo if the assert above has not been triggered for a long time, + /// then removed the autoresize code below if( net >= (int) m_nets.size() ) // Autoresize m_nets.resize( net + 1 ); } else if( aItem->Type() == PCB_MODULE_T ) { const MODULE* module = static_cast( aItem ); + for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() ) { net = pad->GetNetCode(); @@ -1056,16 +1061,26 @@ void RN_DATA::Add( const BOARD_ITEM* aItem ) if( net < 1 ) // do not process unconnected items continue; + wxASSERT( (unsigned) net < m_nets.size() ); + /// @todo if the assert above has not been triggered for a long time, + /// then removed the autoresize code below if( net >= (int) m_nets.size() ) // Autoresize m_nets.resize( net + 1 ); m_nets[net].AddItem( pad ); } - return; + return true; + } + else if( aItem->Type() == PCB_NETINFO_T ) + { + int netCount = m_board->GetNetCount(); + + if( (unsigned) netCount > m_nets.size() ) + m_nets.resize( netCount ); + + return true; } - else - return; switch( aItem->Type() ) { @@ -1086,12 +1101,15 @@ void RN_DATA::Add( const BOARD_ITEM* aItem ) break; default: + return false; break; } + + return true; } -void RN_DATA::Remove( const BOARD_ITEM* aItem ) +bool RN_DATA::Remove( const BOARD_ITEM* aItem ) { int net; @@ -1100,21 +1118,23 @@ void RN_DATA::Remove( const BOARD_ITEM* aItem ) net = static_cast( aItem )->GetNetCode(); if( net < 1 ) // do not process unconnected items - return; + return false; + wxASSERT( (unsigned) net < m_nets.size() ); + /// @todo if the assert above has not been triggered for a long time, + /// then removed the autoresize code below #ifdef NDEBUG if( net >= (int) m_nets.size() ) // Autoresize { m_nets.resize( net + 1 ); - - return; // if it was resized, then surely the item had not been added before + return false; // if it was resized, then surely the item had not been added before } #endif - assert( net < (int) m_nets.size() ); } else if( aItem->Type() == PCB_MODULE_T ) { const MODULE* module = static_cast( aItem ); + for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() ) { net = pad->GetNetCode(); @@ -1122,23 +1142,26 @@ void RN_DATA::Remove( const BOARD_ITEM* aItem ) if( net < 1 ) // do not process unconnected items continue; + wxASSERT( (unsigned) net < m_nets.size() ); + /// @todo if the assert above has not been triggered for a long time, + /// then removed the autoresize code below #ifdef NDEBUG if( net >= (int) m_nets.size() ) // Autoresize { m_nets.resize( net + 1 ); - - return; // if it was resized, then surely the item had not been added before + return false; // if it was resized, then surely the item had not been added before } #endif - assert( net < (int) m_nets.size() ); m_nets[net].RemoveItem( pad ); } - return; + return true; } else - return; + { + return false; + } switch( aItem->Type() ) { @@ -1159,15 +1182,24 @@ void RN_DATA::Remove( const BOARD_ITEM* aItem ) break; default: + return false; break; } + + return true; } -void RN_DATA::Update( const BOARD_ITEM* aItem ) +bool RN_DATA::Update( const BOARD_ITEM* aItem ) { - Remove( aItem ); - Add( aItem ); + if( Remove( aItem ) ) + { + bool res = Add( aItem ); + assert( res ); + return true; + } + + return false; } diff --git a/pcbnew/ratsnest_data.h b/pcbnew/ratsnest_data.h index d272e7903e..134e32e3e8 100644 --- a/pcbnew/ratsnest_data.h +++ b/pcbnew/ratsnest_data.h @@ -647,22 +647,26 @@ public: * Function Add() * Adds an item to the ratsnest data. * @param aItem is an item to be added. + * @return True if operation succeeded. */ - void Add( const BOARD_ITEM* aItem ); + bool Add( const BOARD_ITEM* aItem ); /** * Function Remove() * Removes an item from the ratsnest data. * @param aItem is an item to be updated. + * @return True if operation succeeded. */ - void Remove( const BOARD_ITEM* aItem ); + bool Remove( const BOARD_ITEM* aItem ); /** * Function Update() * Updates the ratsnest data for an item. * @param aItem is an item to be updated. + * @return True if operation succeeded. The item will not be updated if it was not previously + * added to the ratsnest. */ - void Update( const BOARD_ITEM* aItem ); + bool Update( const BOARD_ITEM* aItem ); /** * Function AddSimple() From d33672cce76157abc50978978f58b9de647c66ab Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 5 Sep 2016 12:19:30 +0200 Subject: [PATCH 53/61] Added missing break --- pcbnew/class_board.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 4e1898cff1..b456f47b63 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -870,6 +870,7 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode ) { case PCB_NETINFO_T: m_NetInfo.AppendNet( (NETINFO_ITEM*) aBoardItem ); + break; // this one uses a vector case PCB_MARKER_T: From 77f74646af49897715bfdce041bccea52cdd8a65 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 5 Sep 2016 12:21:17 +0200 Subject: [PATCH 54/61] Auto update ratsnest data on net change --- pcbnew/class_board_connected_item.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pcbnew/class_board_connected_item.cpp b/pcbnew/class_board_connected_item.cpp index e996648b1b..b7162e7884 100644 --- a/pcbnew/class_board_connected_item.cpp +++ b/pcbnew/class_board_connected_item.cpp @@ -34,6 +34,8 @@ #include #include +#include + BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) : BOARD_ITEM( aParent, idtype ), m_netinfo( &NETINFO_LIST::ORPHANED_ITEM ), m_Subnet( 0 ), m_ZoneSubnet( 0 ) @@ -48,6 +50,11 @@ bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert ) // set the m_netinfo to the dummy NETINFO_LIST::ORPHANED BOARD* board = GetBoard(); + RN_DATA* ratsnest = board ? board->GetRatsnest() : NULL; + bool addRatsnest = false; + + if( ratsnest ) + addRatsnest = ratsnest->Remove( this ); if( ( aNetCode >= 0 ) && board ) m_netinfo = board->FindNet( aNetCode ); @@ -57,6 +64,10 @@ bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert ) if( !aNoAssert ) assert( m_netinfo ); + // Add only if it was previously added to the ratsnest + if( addRatsnest ) + ratsnest->Add( this ); + return ( m_netinfo != NULL ); } From 0cc2c87ef8801fb6393aac948c039a7c14101f38 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 5 Sep 2016 12:22:24 +0200 Subject: [PATCH 55/61] Removed BOARD::AppendNet() It is handled by BOARD::Add() now. --- pcbnew/class_board.cpp | 2 +- pcbnew/class_board.h | 10 ---------- pcbnew/eagle_plugin.cpp | 2 +- pcbnew/legacy_plugin.cpp | 2 +- pcbnew/pcad2kicadpcb_plugin/pcb.cpp | 2 +- pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp | 2 +- pcbnew/pcb_parser.cpp | 6 +++--- 7 files changed, 8 insertions(+), 18 deletions(-) diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index b456f47b63..fd82c2b7d9 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -2595,7 +2595,7 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets, { // It is a new net, we have to add it netinfo = new NETINFO_ITEM( this, net.GetNetName() ); - m_NetInfo.AppendNet( netinfo ); + Add( netinfo ); } pad->SetNetCode( netinfo->GetNet() ); diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index 09caae0458..7035e19102 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -784,16 +784,6 @@ public: */ NETINFO_ITEM* FindNet( const wxString& aNetname ) const; - /** - * Function AppendNet - * adds a new net description item to the current board. - * @param aNewNet is the new description item. - */ - void AppendNet( NETINFO_ITEM* aNewNet ) - { - m_NetInfo.AppendNet( aNewNet ); - } - NETINFO_LIST& GetNetInfo() { return m_NetInfo; diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp index 8e51b5763c..55f6108cba 100644 --- a/pcbnew/eagle_plugin.cpp +++ b/pcbnew/eagle_plugin.cpp @@ -2622,7 +2622,7 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals ) const string& nname = net->second.get( ".name" ); wxString netName = FROM_UTF8( nname.c_str() ); - m_board->AppendNet( new NETINFO_ITEM( m_board, netName, netCode ) ); + m_board->Add( new NETINFO_ITEM( m_board, netName, netCode ) ); m_xpath->Value( nname.c_str() ); diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index d5a0988c21..bc8f23c7ef 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -2080,7 +2080,7 @@ void LEGACY_PLUGIN::loadNETINFO_ITEM() // if it is not the net 0, or if the net 0 does not exists. if( net && ( net->GetNet() > 0 || m_board->FindNet( 0 ) == NULL ) ) { - m_board->AppendNet( net ); + m_board->Add( net ); // Be sure we have room to store the net in m_netCodes if( (int)m_netCodes.size() <= netCode ) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb.cpp index feedb83135..1b27a8f725 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb.cpp @@ -925,7 +925,7 @@ void PCB::AddToBoard() { net = m_pcbNetlist[i]; - m_board->AppendNet( new NETINFO_ITEM( m_board, net->m_name, net->m_netCode ) ); + m_board->Add( new NETINFO_ITEM( m_board, net->m_name, net->m_netCode ) ); } for( i = 0; i < (int) m_pcbComponents.GetCount(); i++ ) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp index f1e9b91723..716a7cf9bb 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp @@ -278,7 +278,7 @@ void PCB_PAD::AddToModule( MODULE* aModule, int aRotation, bool aEncapsulatedPad { // It is a new net netinfo = new NETINFO_ITEM( m_board, m_net ); - m_board->AppendNet( netinfo ); + m_board->Add( netinfo ); } pad->SetNetCode( netinfo->GetNet() ); diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index e6413c878d..228cbe9913 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -1242,10 +1242,10 @@ void PCB_PARSER::parseNETINFO_ITEM() throw( IO_ERROR, PARSE_ERROR ) // net 0 should be already in list, so store this net // if it is not the net 0, or if the net 0 does not exists. // (TODO: a better test.) - if( netCode > 0 || m_board->FindNet( 0 ) == NULL ) + if( netCode > NETINFO_LIST::UNCONNECTED || !m_board->FindNet( NETINFO_LIST::UNCONNECTED ) ) { NETINFO_ITEM* net = new NETINFO_ITEM( m_board, name, netCode ); - m_board->AppendNet( net ); + m_board->Add( net ); // Store the new code mapping pushValueIntoMap( netCode, net->GetNet() ); @@ -2988,7 +2988,7 @@ ZONE_CONTAINER* PCB_PARSER::parseZONE_CONTAINER() throw( IO_ERROR, PARSE_ERROR ) { int newnetcode = m_board->GetNetCount(); net = new NETINFO_ITEM( m_board, netnameFromfile, newnetcode ); - m_board->AppendNet( net ); + m_board->Add( net ); // Store the new code mapping pushValueIntoMap( newnetcode, net->GetNet() ); From 3bcbe0dfbdbe22c8a8ff08f40a21b2c094879077 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 5 Sep 2016 15:28:53 +0200 Subject: [PATCH 56/61] GAL ratsnest code cleanup --- pcbnew/pcbframe.cpp | 13 ++----------- pcbnew/ratsnest_data.cpp | 31 ++++++++----------------------- pcbnew/undo_redo.cpp | 15 +++------------ 3 files changed, 13 insertions(+), 46 deletions(-) diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 5153f42b9b..df6f0bd4c0 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -481,7 +481,7 @@ void PCB_EDIT_FRAME::SetBoard( BOARD* aBoard ) if( IsGalCanvasActive() ) { - aBoard->GetRatsnest()->Recalculate(); + aBoard->GetRatsnest()->ProcessBoard(); // reload the worksheet SetPageSettings( aBoard->GetPageSettings() ); @@ -673,17 +673,8 @@ void PCB_EDIT_FRAME::Show3D_Frame( wxCommandEvent& event ) void PCB_EDIT_FRAME::UseGalCanvas( bool aEnable ) { - if( aEnable ) - { - BOARD* board = GetBoard(); - - if( board ) - board->GetRatsnest()->ProcessBoard(); - } - else - { + if( !aEnable ) Compile_Ratsnest( NULL, true ); - } PCB_BASE_EDIT_FRAME::UseGalCanvas( aEnable ); diff --git a/pcbnew/ratsnest_data.cpp b/pcbnew/ratsnest_data.cpp index 6fcf592214..93f1084a8a 100644 --- a/pcbnew/ratsnest_data.cpp +++ b/pcbnew/ratsnest_data.cpp @@ -1044,10 +1044,8 @@ bool RN_DATA::Add( const BOARD_ITEM* aItem ) if( net < 1 ) // do not process unconnected items return false; - wxASSERT( (unsigned) net < m_nets.size() ); - /// @todo if the assert above has not been triggered for a long time, - /// then removed the autoresize code below - if( net >= (int) m_nets.size() ) // Autoresize + // Autoresize is necessary e.g. for module editor + if( net >= (int) m_nets.size() ) m_nets.resize( net + 1 ); } else if( aItem->Type() == PCB_MODULE_T ) @@ -1061,10 +1059,8 @@ bool RN_DATA::Add( const BOARD_ITEM* aItem ) if( net < 1 ) // do not process unconnected items continue; - wxASSERT( (unsigned) net < m_nets.size() ); - /// @todo if the assert above has not been triggered for a long time, - /// then removed the autoresize code below - if( net >= (int) m_nets.size() ) // Autoresize + // Autoresize is necessary e.g. for module editor + if( net >= (int) m_nets.size() ) m_nets.resize( net + 1 ); m_nets[net].AddItem( pad ); @@ -1120,16 +1116,12 @@ bool RN_DATA::Remove( const BOARD_ITEM* aItem ) if( net < 1 ) // do not process unconnected items return false; - wxASSERT( (unsigned) net < m_nets.size() ); - /// @todo if the assert above has not been triggered for a long time, - /// then removed the autoresize code below -#ifdef NDEBUG - if( net >= (int) m_nets.size() ) // Autoresize + // Autoresize is necessary e.g. for module editor + if( net >= (int) m_nets.size() ) { m_nets.resize( net + 1 ); return false; // if it was resized, then surely the item had not been added before } -#endif } else if( aItem->Type() == PCB_MODULE_T ) { @@ -1142,16 +1134,12 @@ bool RN_DATA::Remove( const BOARD_ITEM* aItem ) if( net < 1 ) // do not process unconnected items continue; - wxASSERT( (unsigned) net < m_nets.size() ); - /// @todo if the assert above has not been triggered for a long time, - /// then removed the autoresize code below -#ifdef NDEBUG - if( net >= (int) m_nets.size() ) // Autoresize + // Autoresize is necessary e.g. for module editor + if( net >= (int) m_nets.size() ) { m_nets.resize( net + 1 ); return false; // if it was resized, then surely the item had not been added before } -#endif m_nets[net].RemoveItem( pad ); } @@ -1259,9 +1247,6 @@ void RN_DATA::Recalculate( int aNet ) { unsigned int netCount = m_board->GetNetCount(); - if( netCount > m_nets.size() ) - m_nets.resize( netCount ); - if( aNet < 0 && netCount > 1 ) // Recompute everything { #ifdef PROFILE diff --git a/pcbnew/undo_redo.cpp b/pcbnew/undo_redo.cpp index d184bb204d..cd6e3d0900 100644 --- a/pcbnew/undo_redo.cpp +++ b/pcbnew/undo_redo.cpp @@ -501,8 +501,8 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool MODULE* module = static_cast( item ); module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1) ); } - view->Add( item ); + view->Add( item ); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); build_item_list = true; break; @@ -552,17 +552,8 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool { // Compile ratsnest propagates nets from pads to tracks /// @todo LEGACY Compile_Ratsnest() has to be rewritten and moved to RN_DATA - Compile_Ratsnest( NULL, true ); - - if( GetModel()->Type() == PCB_T ) - { - /// @todo LEGACY Compile_Ratsnest() might have changed nets for tracks, - //so we need to refresh them - BOARD* board = static_cast( GetModel() ); - - for( TRACK* track = board->m_Track; track; track = track->Next() ) - track->ViewUpdate(); - } + if( deep_reBuild_ratsnest ) + Compile_Ratsnest( NULL, false ); if( IsGalCanvasActive() ) { From 3425624510c7f9350fd1cbb33bb76b05ca1fa2ca Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 5 Sep 2016 15:35:14 +0200 Subject: [PATCH 57/61] Compile_Ratsnest() refreshes track labels --- pcbnew/connect.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pcbnew/connect.cpp b/pcbnew/connect.cpp index 848c30b531..50c3805cf9 100644 --- a/pcbnew/connect.cpp +++ b/pcbnew/connect.cpp @@ -942,6 +942,10 @@ void PCB_BASE_FRAME::RecalculateAllTracksNetcode() } } + /// @todo LEGACY tracks might have changed their nets, so we need to refresh labels in GAL + for( TRACK* track = m_Pcb->m_Track; track; track = track->Next() ) + track->ViewUpdate(); + // Sort the track list by net codes: RebuildTrackChain( m_Pcb ); } From c52a9d850b652fcb652335f53cc6a9ec7fde7456 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 5 Sep 2016 15:38:01 +0200 Subject: [PATCH 58/61] Converted netlist updater to use BOARD_COMMIT Fixes: lp:1579910 * https://bugs.launchpad.net/kicad/+bug/1579910 --- pcbnew/board_netlist_updater.cpp | 89 +++++++++++----------------- pcbnew/board_netlist_updater.h | 9 +-- pcbnew/class_board_connected_item.h | 10 ++++ pcbnew/dialogs/dialog_update_pcb.cpp | 28 ++------- 4 files changed, 51 insertions(+), 85 deletions(-) diff --git a/pcbnew/board_netlist_updater.cpp b/pcbnew/board_netlist_updater.cpp index d0dc086986..7088798302 100644 --- a/pcbnew/board_netlist_updater.cpp +++ b/pcbnew/board_netlist_updater.cpp @@ -50,11 +50,11 @@ BOARD_NETLIST_UPDATER::BOARD_NETLIST_UPDATER( PCB_EDIT_FRAME* aFrame, BOARD* aBoard ) : + m_commit( aFrame ), m_frame( aFrame ), m_board( aBoard ) { m_reporter = &NULL_REPORTER::GetInstance(); - m_undoList = new PICKED_ITEMS_LIST; m_deleteSinglePadNets = true; m_deleteUnusedComponents = false; @@ -69,23 +69,6 @@ BOARD_NETLIST_UPDATER::BOARD_NETLIST_UPDATER( PCB_EDIT_FRAME* aFrame, BOARD* aBo BOARD_NETLIST_UPDATER::~BOARD_NETLIST_UPDATER() { - delete m_undoList; -} - - -void BOARD_NETLIST_UPDATER::pushUndo( BOARD_ITEM* aItem, UNDO_REDO_T aCommandType, BOARD_ITEM* aCopy ) -{ - ITEM_PICKER picker( aItem, aCommandType ); - - if( aCommandType == UR_CHANGED ) - { - if( m_undoList->FindItem( aItem ) >= 0 ) // add only once - return; - - picker.SetLink( aCopy ? aCopy : aItem->Clone() ); - } - - m_undoList->PushItem( picker ); } @@ -143,10 +126,8 @@ MODULE* BOARD_NETLIST_UPDATER::addNewComponent( COMPONENT* aComponent ) footprint->SetPosition( estimateComponentInsertionPosition( ) ); footprint->SetTimeStamp( GetNewTimeStamp() ); - m_board->Add( footprint, ADD_APPEND ); m_addedComponents.push_back( footprint ); - - pushUndo( footprint, UR_NEW ); + m_commit.Add( footprint ); return footprint; } @@ -205,7 +186,9 @@ MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE* aPcb if( !m_isDryRun ) { wxASSERT( aPcbComponent != NULL ); + MODULE* newFootprint = new MODULE( *aNewComponent->GetModule() ); + newFootprint->SetParent( m_board ); if( aNetlist.IsFindByTimeStamp() ) newFootprint->SetReference( aPcbComponent->GetReference() ); @@ -213,11 +196,8 @@ MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE* aPcb newFootprint->SetPath( aPcbComponent->GetPath() ); aPcbComponent->CopyNetlistSettings( newFootprint, false ); - m_board->Remove( aPcbComponent ); - m_board->Add( newFootprint, ADD_APPEND ); - - pushUndo( aPcbComponent, UR_DELETED ); - pushUndo( newFootprint, UR_NEW ); + m_commit.Remove( aPcbComponent ); + m_commit.Add( newFootprint ); return newFootprint; } @@ -314,7 +294,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE* aPcbComponent, CO m_reporter->Report( msg, REPORTER::RPT_INFO ); - if ( !m_isDryRun ) + if( !m_isDryRun ) { changed = true; aPcbComponent->SetPath( aNewComponent->GetTimeStamp() ); @@ -322,7 +302,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE* aPcbComponent, CO } if( changed ) - pushUndo( aPcbComponent, UR_CHANGED, copy ); + m_commit.Modified( aPcbComponent, copy ); else delete copy; @@ -368,21 +348,30 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent { if( net.GetNetName() != pad->GetNetname() ) { - NETINFO_ITEM* netinfo = m_board->FindNet( net.GetNetName() ); + const wxString& netName = net.GetNetName(); + NETINFO_ITEM* netinfo = m_board->FindNet( netName ); - if( netinfo == NULL ) + if( netinfo == nullptr ) + { + // It might be a new net that has not been added to the board yet + auto netIt = m_addedNets.find( netName ); + + if( netIt != m_addedNets.end() ) + netinfo = netIt->second; + } + + if( netinfo == nullptr ) { // It is a new net, we have to add it if( !m_isDryRun ) { changed = true; - netinfo = new NETINFO_ITEM( m_board, net.GetNetName() ); - m_board->AppendNet( netinfo ); - pushUndo( netinfo, UR_NEW ); + netinfo = new NETINFO_ITEM( m_board, netName ); + m_commit.Add( netinfo ); + m_addedNets[netName] = netinfo; } - msg.Printf( _( "Add net %s.\n" ), GetChars( net.GetNetName() ) ); - + msg.Printf( _( "Add net %s.\n" ), GetChars( netName ) ); m_reporter->Report( msg, REPORTER::RPT_ACTION ); } @@ -392,13 +381,13 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent GetChars( aPcbComponent->GetReference() ), GetChars( pad->GetPadName() ), GetChars( pad->GetNetname() ), - GetChars( net.GetNetName() ) ); + GetChars( netName ) ); } else { msg.Printf( _( "Connect component %s pin %s to net %s.\n"), GetChars( aPcbComponent->GetReference() ), GetChars( pad->GetPadName() ), - GetChars( net.GetNetName() ) ); + GetChars( netName ) ); } m_reporter->Report( msg, REPORTER::RPT_ACTION ); @@ -409,21 +398,20 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent GetChars( aPcbComponent->GetPath() ), GetChars( pad->GetPadName() ), GetChars( pad->GetNetname() ), - GetChars( net.GetNetName() ) ); - + GetChars( netName ) ); m_reporter->Report( msg, REPORTER::RPT_INFO ); if( !m_isDryRun ) { changed = true; - pad->SetNetCode( netinfo->GetNet() ); + pad->SetNet( netinfo ); } } } } if( changed ) - pushUndo( aPcbComponent, UR_CHANGED, copy ); + m_commit.Modified( aPcbComponent, copy ); else delete copy; @@ -461,10 +449,7 @@ bool BOARD_NETLIST_UPDATER::deleteUnusedComponents( NETLIST& aNetlist ) m_reporter->Report( msg, REPORTER::RPT_INFO ); if( !m_isDryRun ) - { - pushUndo( module, UR_DELETED ); - m_board->Remove( module ); - } + m_commit.Remove( module ); } } @@ -533,7 +518,6 @@ bool BOARD_NETLIST_UPDATER::deleteSinglePadNets() GetChars( previouspad->GetPadName() ) ); m_reporter->Report( msg, REPORTER::RPT_ACTION ); - //pushUndo( previouspad, UR_CHANGED ); previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED ); } } @@ -551,10 +535,8 @@ bool BOARD_NETLIST_UPDATER::deleteSinglePadNets() // Examine last pad if( pad && count == 1 ) - { - //pushUndo( pad, UR_CHANGED ); pad->SetNetCode( NETINFO_LIST::UNCONNECTED ); - } + return true; } @@ -679,14 +661,11 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist ) if( m_deleteSinglePadNets ) deleteSinglePadNets(); - if ( !m_isDryRun ) + if( !m_isDryRun ) { - m_frame->SaveCopyInUndoList( *m_undoList, UR_UNSPECIFIED, wxPoint( 0, 0 ) ); - m_frame->OnModify(); - - m_frame->Compile_Ratsnest( NULL, true ); + m_commit.Push( _( "Update netlist" ) ); + m_frame->Compile_Ratsnest( NULL, false ); m_board->GetRatsnest()->ProcessBoard(); - testConnectivity( aNetlist ); } diff --git a/pcbnew/board_netlist_updater.h b/pcbnew/board_netlist_updater.h index cf3cba506f..256722ddc6 100644 --- a/pcbnew/board_netlist_updater.h +++ b/pcbnew/board_netlist_updater.h @@ -39,10 +39,9 @@ class REPORTER; class NETLIST; class COMPONENT; class MODULE; -class PICKED_ITEMS_LIST; class PCB_EDIT_FRAME; -#include +#include /** * Class BOARD_NETLIST_UPDATER @@ -130,9 +129,6 @@ public: } private: - - void pushUndo( BOARD_ITEM* aItem, UNDO_REDO_T aCommandType, BOARD_ITEM* aCopy = NULL ); - wxPoint estimateComponentInsertionPosition(); MODULE* addNewComponent( COMPONENT* aComponent ); MODULE* replaceComponent( NETLIST& aNetlist, MODULE* aPcbComponent, COMPONENT* aNewComponent ); @@ -142,12 +138,13 @@ private: bool deleteSinglePadNets(); bool testConnectivity( NETLIST& aNetlist ); - PICKED_ITEMS_LIST* m_undoList; + BOARD_COMMIT m_commit; PCB_EDIT_FRAME* m_frame; BOARD* m_board; REPORTER* m_reporter; std::vector m_addedComponents; + std::map m_addedNets; bool m_deleteSinglePadNets; bool m_deleteUnusedComponents; diff --git a/pcbnew/class_board_connected_item.h b/pcbnew/class_board_connected_item.h index cd694577ef..6687f0ab3a 100644 --- a/pcbnew/class_board_connected_item.h +++ b/pcbnew/class_board_connected_item.h @@ -92,6 +92,16 @@ public: return m_netinfo; } + /** + * Function SetNet + * Sets a NET_INFO object for the item. + */ + void SetNet( NETINFO_ITEM* aNetInfo ) + { + assert( aNetInfo->GetBoard() == GetBoard() ); + m_netinfo = aNetInfo; + } + /** * Function GetNetCode * @return int - the net code. diff --git a/pcbnew/dialogs/dialog_update_pcb.cpp b/pcbnew/dialogs/dialog_update_pcb.cpp index 18f08a16f7..39f7cbe458 100644 --- a/pcbnew/dialogs/dialog_update_pcb.cpp +++ b/pcbnew/dialogs/dialog_update_pcb.cpp @@ -43,12 +43,6 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) if( !aDryRun ) { - // Remove old modules - for( MODULE* module = board->m_Modules; module; module = module->Next() ) - { - module->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) ); - view->Remove( module ); - } // Clear selection, just in case a selected item has to be removed toolManager->RunAction( COMMON_ACTIONS::selectionClear, true ); @@ -85,28 +79,14 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) if( aDryRun ) return; - std::vector newFootprints = updater.GetAddedComponents(); - - m_frame->OnModify(); m_frame->SetCurItem( NULL ); - - // Reload modules - for( MODULE* module = board->m_Modules; module; module = module->Next() ) - { - module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1 ) ); - view->Add( module ); - module->ViewUpdate(); - } - - // Rebuild the board connectivity: - if( m_frame->IsGalCanvasActive() ) - board->GetRatsnest()->ProcessBoard(); - - m_frame->Compile_Ratsnest( NULL, true ); m_frame->SetMsgPanel( board ); if( m_frame->IsGalCanvasActive() ) { + std::vector newFootprints = updater.GetAddedComponents(); + + // Place the new modules m_frame->SpreadFootprints( &newFootprints, false, false, m_frame->GetCrossHairPosition() ); if( !newFootprints.empty() ) @@ -122,7 +102,7 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) m_btnPerformUpdate->Enable( false ); m_btnPerformUpdate->SetLabel( _( "Update complete" ) ); - m_btnCancel->SetLabel( _("Close") ); + m_btnCancel->SetLabel( _( "Close" ) ); m_btnCancel->SetFocus(); } From 02cfab42660b2312bbc794e503699344aa0b5ef6 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 5 Sep 2016 15:46:29 +0200 Subject: [PATCH 59/61] Display a message when a locked component is not removed --- pcbnew/board_netlist_updater.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pcbnew/board_netlist_updater.cpp b/pcbnew/board_netlist_updater.cpp index 7088798302..ffe5cac447 100644 --- a/pcbnew/board_netlist_updater.cpp +++ b/pcbnew/board_netlist_updater.cpp @@ -429,9 +429,6 @@ bool BOARD_NETLIST_UPDATER::deleteUnusedComponents( NETLIST& aNetlist ) { nextModule = module->Next(); - if( module->IsLocked() ) - continue; - if( m_lookupByTimestamp ) component = aNetlist.GetComponentByTimeStamp( module->GetPath() ); else @@ -439,6 +436,14 @@ bool BOARD_NETLIST_UPDATER::deleteUnusedComponents( NETLIST& aNetlist ) if( component == NULL ) { + if( module->IsLocked() ) + { + msg.Printf( _( "Component %s is locked, skipping removal.\n" ), + GetChars( module->GetReference() ) ); + m_reporter->Report( msg, REPORTER::RPT_INFO ); + continue; + } + msg.Printf( _( "Remove component %s." ), GetChars( module->GetReference() ) ); m_reporter->Report( msg, REPORTER::RPT_ACTION ); From 03f4a89521b25541ada0e4503f04635e9995d444 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 13 Sep 2016 10:06:25 +0200 Subject: [PATCH 60/61] More descriptive method names for RN_NODE --- include/ttl/halfedge/hetriang.h | 19 +++++++++++++++++-- pcbnew/ratsnest_data.cpp | 12 ++++++------ pcbnew/ratsnest_data.h | 12 ++++++------ pcbnew/ratsnest_viewitem.cpp | 2 +- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/include/ttl/halfedge/hetriang.h b/include/ttl/halfedge/hetriang.h index e10af65aad..91a6354ce0 100644 --- a/include/ttl/halfedge/hetriang.h +++ b/include/ttl/halfedge/hetriang.h @@ -43,7 +43,7 @@ #define _HE_TRIANG_H_ //#define TTL_USE_NODE_ID // Each node gets it's own unique id -#define TTL_USE_NODE_FLAG // Each node gets a flag (can be set to true or false) +//#define TTL_USE_NODE_FLAG // Each node gets a flag (can be set to true or false) #include #include @@ -106,6 +106,9 @@ protected: /// Tag for quick connection resolution int m_tag; + /// Whether it the node can be a target for ratsnest lines + bool m_noline; + /// List of board items that share this node std::unordered_set m_parents; @@ -124,7 +127,7 @@ public: #ifdef TTL_USE_NODE_ID m_id( id_count++ ), #endif - m_x( aX ), m_y( aY ), m_tag( -1 ) + m_x( aX ), m_y( aY ), m_tag( -1 ), m_noline( false ) { m_layers.reset(); } @@ -156,6 +159,18 @@ public: m_tag = aTag; } + /// Decides whether this node can be a ratsnest line target + inline void SetNoLine( bool aEnable ) + { + m_noline = aEnable; + } + + /// Returns true if this node can be a target for ratsnest lines + inline const bool& GetNoLine() const + { + return m_noline; + } + #ifdef TTL_USE_NODE_ID /// Returns the id (TTL_USE_NODE_ID must be defined) inline int Id() const diff --git a/pcbnew/ratsnest_data.cpp b/pcbnew/ratsnest_data.cpp index 93f1084a8a..9735814800 100644 --- a/pcbnew/ratsnest_data.cpp +++ b/pcbnew/ratsnest_data.cpp @@ -215,11 +215,11 @@ void RN_NET::validateEdge( RN_EDGE_MST_PTR& aEdge ) // If any of nodes belonging to the edge has the flag set, // change it to the closest node that has flag cleared - if( source->GetFlag() ) + if( source->GetNoLine() ) { valid = false; + std::list closest = GetClosestNodes( source, LINE_TARGET() ); - std::list closest = GetClosestNodes( source, WITHOUT_FLAG() ); for( RN_NODE_PTR& node : closest ) { if( node && node != target ) @@ -230,11 +230,11 @@ void RN_NET::validateEdge( RN_EDGE_MST_PTR& aEdge ) } } - if( target->GetFlag() ) + if( target->GetNoLine() ) { valid = false; + std::list closest = GetClosestNodes( target, LINE_TARGET() ); - std::list closest = GetClosestNodes( target, WITHOUT_FLAG() ); for( RN_NODE_PTR& node : closest ) { if( node && node != source ) @@ -398,7 +398,7 @@ RN_POLY::RN_POLY( const SHAPE_POLY_SET* aParent, // Mark it as not appropriate as a destination of ratsnest edges // (edges coming out from a polygon vertex look weird) - m_node->SetFlag( true ); + m_node->SetNoLine( true ); } @@ -761,7 +761,7 @@ void RN_NET::GetAllItems( std::list& aOutput, RN_ITEM_TYP void RN_NET::ClearSimple() { for( const RN_NODE_PTR& node : m_blockedNodes ) - node->SetFlag( false ); + node->SetNoLine( false ); m_blockedNodes.clear(); m_simpleNodes.clear(); diff --git a/pcbnew/ratsnest_data.h b/pcbnew/ratsnest_data.h index 134e32e3e8..71dc17cf90 100644 --- a/pcbnew/ratsnest_data.h +++ b/pcbnew/ratsnest_data.h @@ -92,19 +92,19 @@ struct RN_NODE_FILTER : public std::unary_function RN_NODE_AND_FILTER operator&&( const RN_NODE_FILTER& aFilter1, const RN_NODE_FILTER& aFilter2 ); RN_NODE_OR_FILTER operator||( const RN_NODE_FILTER& aFilter1, const RN_NODE_FILTER& aFilter2 ); -///> Filters out nodes that have the flag set. -struct WITHOUT_FLAG : public RN_NODE_FILTER +///> Filters out nodes that cannot be a ratsnest line target +struct LINE_TARGET : public RN_NODE_FILTER { bool operator()( const RN_NODE_PTR& aNode ) const { - return !aNode->GetFlag(); + return !aNode->GetNoLine(); } }; ///> Filters out nodes with a specific tag -struct DIFFERENT_TAG : public RN_NODE_FILTER +struct DIFF_TAG : public RN_NODE_FILTER { - DIFFERENT_TAG( int aTag ) : + DIFF_TAG( int aTag ) : m_tag( aTag ) {} @@ -515,7 +515,7 @@ public: inline void AddBlockedNode( RN_NODE_PTR& aNode ) { m_blockedNodes.insert( aNode ); - aNode->SetFlag( true ); + aNode->SetNoLine( true ); } /** diff --git a/pcbnew/ratsnest_viewitem.cpp b/pcbnew/ratsnest_viewitem.cpp index a2b6c89bbb..9561b2e6c4 100644 --- a/pcbnew/ratsnest_viewitem.cpp +++ b/pcbnew/ratsnest_viewitem.cpp @@ -79,7 +79,7 @@ void RATSNEST_VIEWITEM::ViewDraw( int aLayer, GAL* aGal ) const if( node->GetRefCount() > 1 ) continue; - RN_NODE_PTR dest = net.GetClosestNode( node, WITHOUT_FLAG() ); + RN_NODE_PTR dest = net.GetClosestNode( node, LINE_TARGET() ); if( dest ) { From 17806b58f61b62f571f644cf40e1ea8d75c1a0bd Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 13 Sep 2016 10:06:49 +0200 Subject: [PATCH 61/61] Fixed unused variable warnings --- pcbnew/dialogs/dialog_update_pcb.cpp | 3 +-- pcbnew/router/pns_kicad_iface.cpp | 1 - pcbnew/router/router_tool.cpp | 5 ----- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/pcbnew/dialogs/dialog_update_pcb.cpp b/pcbnew/dialogs/dialog_update_pcb.cpp index 39f7cbe458..ff35ec52cd 100644 --- a/pcbnew/dialogs/dialog_update_pcb.cpp +++ b/pcbnew/dialogs/dialog_update_pcb.cpp @@ -36,8 +36,7 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) { m_messagePanel->Clear(); - REPORTER &reporter = m_messagePanel->Reporter(); - KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); + REPORTER& reporter = m_messagePanel->Reporter(); TOOL_MANAGER* toolManager = m_frame->GetToolManager(); BOARD* board = m_frame->GetBoard(); diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 79f3ae68d9..db8c42580c 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -741,7 +741,6 @@ void PNS_KICAD_IFACE::SyncWorld( PNS::NODE *aWorld ) for( TRACK* t = m_board->m_Track; t; t = t->Next() ) { KICAD_T type = t->Type(); - PNS::ITEM* item = NULL; if( type == PCB_TRACE_T ) { std::unique_ptr< PNS::SEGMENT > segment = syncTrack( t ); diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index c7b6efa7d6..79f71a2205 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -756,8 +756,6 @@ void ROUTER_TOOL::performDragging() ctls->SetAutoPan( true ); - bool modified = false; - while( OPT_TOOL_EVENT evt = Wait() ) { ctls->ForceCursorPosition( false ); @@ -772,10 +770,7 @@ void ROUTER_TOOL::performDragging() else if( evt->IsClick( BUT_LEFT ) ) { if( m_router->FixRoute( m_endSnapPoint, m_endItem ) ) - { - modified = true; break; - } } handleCommonEvents( *evt );