From e2cc78b2b5f76cc1582e713a649b639286ab5127 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 1 Jun 2016 11:28:07 +0200 Subject: [PATCH] Code cleanup: remove dead code (some removed methods were broken), and update or add comments. --- include/class_board_item.h | 8 ------- pcbnew/array_creator.cpp | 5 +--- pcbnew/block.cpp | 3 --- pcbnew/block_module_editor.cpp | 7 ++---- pcbnew/class_board.cpp | 43 +--------------------------------- pcbnew/class_board.h | 12 ++++------ pcbnew/class_module.cpp | 36 ++++------------------------ pcbnew/class_module.h | 19 --------------- pcbnew/class_pad.cpp | 7 ------ pcbnew/class_pad.h | 10 ++------ pcbnew/pcb_base_edit_frame.h | 8 +++---- pcbnew/tools/edit_tool.cpp | 2 +- 12 files changed, 20 insertions(+), 140 deletions(-) diff --git a/include/class_board_item.h b/include/class_board_item.h index e532b5d112..6d9a2f928a 100644 --- a/include/class_board_item.h +++ b/include/class_board_item.h @@ -332,14 +332,6 @@ public: /// @copydoc VIEW_ITEM::ViewGetLayers() virtual void ViewGetLayers( int aLayers[], int& aCount ) const; - - /*! - * Function IncrementItemReference - * Implement if the concept of "incrementing" makes sense for an - * item (e.g. modules and pads) - * @return if item reference was incremented - */ - virtual bool IncrementItemReference() { return false; } }; #endif /* BOARD_ITEM_STRUCT_H */ diff --git a/pcbnew/array_creator.cpp b/pcbnew/array_creator.cpp index dee23633a3..537abea823 100644 --- a/pcbnew/array_creator.cpp +++ b/pcbnew/array_creator.cpp @@ -87,7 +87,7 @@ void ARRAY_CREATOR::Invoke() else { // PCB items keep the same numbering - new_item = getBoard()->DuplicateAndAddItem( item, false ); + new_item = getBoard()->DuplicateAndAddItem( item ); // @TODO: we should merge zones. This is a bit tricky, because // the undo command needs saving old area, if it is merged. @@ -96,11 +96,8 @@ void ARRAY_CREATOR::Invoke() if( new_item ) { array_opts->TransformItem( ptN, new_item, rotPoint ); - prePushAction( new_item ); - newItemsList.PushItem( new_item ); // For undo list - postPushAction( new_item ); } diff --git a/pcbnew/block.cpp b/pcbnew/block.cpp index fdbf2d874b..68c4b0db62 100644 --- a/pcbnew/block.cpp +++ b/pcbnew/block.cpp @@ -866,9 +866,6 @@ void PCB_EDIT_FRAME::Block_Duplicate( bool aIncrement ) newitem = (BOARD_ITEM*)item->Clone(); - if( aIncrement ) - newitem->IncrementItemReference(); - if( item->Type() == PCB_MODULE_T ) m_Pcb->m_Status_Pcb = 0; diff --git a/pcbnew/block_module_editor.cpp b/pcbnew/block_module_editor.cpp index c156cc7119..1a635e972f 100644 --- a/pcbnew/block_module_editor.cpp +++ b/pcbnew/block_module_editor.cpp @@ -299,7 +299,7 @@ void FOOTPRINT_EDIT_FRAME::HandleBlockPlace( wxDC* DC ) break; case BLOCK_COPY: // Copy - case BLOCK_COPY_AND_INCREMENT: // Copy and increment references + case BLOCK_COPY_AND_INCREMENT: // Copy and increment pad names GetScreen()->m_BlockLocate.ClearItemsList(); SaveCopyInUndoList( currentModule, UR_MODEDIT ); CopyMarkedItems( currentModule, GetScreen()->m_BlockLocate.GetMoveVector(), @@ -457,7 +457,7 @@ void CopyMarkedItems( MODULE* module, wxPoint offset, bool aIncrement ) module->Pads().PushFront( NewPad ); if( aIncrement ) - NewPad->IncrementItemReference(); + NewPad->IncrementPadName( true, true ); } BOARD_ITEM* newItem; @@ -473,9 +473,6 @@ void CopyMarkedItems( MODULE* module, wxPoint offset, bool aIncrement ) newItem->SetParent( module ); newItem->SetFlags( SELECTED ); module->GraphicalItems().PushFront( newItem ); - - if( aIncrement ) - newItem->IncrementItemReference(); } MoveMarkedItems( module, offset ); diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 4c6db1f32e..fc66e1941c 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -2682,8 +2682,7 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets, } -BOARD_ITEM* BOARD::DuplicateAndAddItem( const BOARD_ITEM* aItem, - bool aIncrementReferences ) +BOARD_ITEM* BOARD::DuplicateAndAddItem( const BOARD_ITEM* aItem ) { BOARD_ITEM* new_item = NULL; @@ -2712,52 +2711,12 @@ BOARD_ITEM* BOARD::DuplicateAndAddItem( const BOARD_ITEM* aItem, } if( new_item ) - { - if( aIncrementReferences ) - new_item->IncrementItemReference(); - Add( new_item ); - } return new_item; } -wxString BOARD::GetNextModuleReferenceWithPrefix( const wxString& aPrefix, - bool aFillSequenceGaps ) -{ - wxString nextRef; - - std::set usedNumbers; - - for( MODULE* module = m_Modules; module; module = module->Next() ) - { - const wxString ref = module->GetReference(); - wxString remainder; - - // ONly interested in modules with the right prefix - if( !ref.StartsWith( aPrefix, &remainder ) ) - continue; - - // the suffix must be a number - if( !remainder.IsNumber() ) - continue; - - long number; - if( remainder.ToCLong( &number ) ) - usedNumbers.insert( number ); - } - - if( usedNumbers.size() ) - { - int nextNum = getNextNumberInSequence( usedNumbers, aFillSequenceGaps ); - nextRef = wxString::Format( wxT( "%s%i" ), aPrefix, nextNum ); - } - - return nextRef; -} - - /* Extracts the board outlines and build a closed polygon * from lines, arcs and circle items on edge cut layer * Any closed outline inside the main outline is a hole diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index ba5241f7ed..5e3e5ed418 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -294,15 +294,13 @@ public: */ BOARD_ITEM* Remove( BOARD_ITEM* aBoardItem ); - BOARD_ITEM* DuplicateAndAddItem( const BOARD_ITEM* aItem, - bool aIncrementReferences ); - /** - * Function GetNextModuleReferenceWithPrefix - * Get the next available module reference with this prefix + * 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. */ - wxString GetNextModuleReferenceWithPrefix( const wxString& aPrefix, - bool aFillSequenceGaps ); + BOARD_ITEM* DuplicateAndAddItem( const BOARD_ITEM* aItem ); /** * Function GetRatsnest() diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 8c518a4425..3b21e3077b 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -1167,12 +1167,13 @@ BOARD_ITEM* MODULE::DuplicateAndAddItem( const BOARD_ITEM* aItem, bool aIncrementPadNumbers ) { BOARD_ITEM* new_item = NULL; + D_PAD* new_pad = NULL; switch( aItem->Type() ) { case PCB_PAD_T: { - D_PAD* new_pad = new D_PAD( *static_cast( aItem ) ); + new_pad = new D_PAD( *static_cast( aItem ) ); Pads().PushBack( new_pad ); new_item = new_pad; @@ -1216,9 +1217,9 @@ BOARD_ITEM* MODULE::DuplicateAndAddItem( const BOARD_ITEM* aItem, break; } - if( aIncrementPadNumbers && new_item ) + if( aIncrementPadNumbers && new_pad ) { - new_item->IncrementItemReference(); + new_pad->IncrementPadName( true, true ); } return new_item; @@ -1264,35 +1265,6 @@ wxString MODULE::GetReferencePrefix() const } -bool MODULE::IncrementItemReference() -{ - // Take the next available module number - return IncrementReference( true ); -} - - -bool MODULE::IncrementReference( bool aFillSequenceGaps ) -{ - BOARD* board = GetBoard(); - - if( !board ) - return false; - - bool success = false; - const wxString prefix = GetReferencePrefix(); - const wxString newReference = board->GetNextModuleReferenceWithPrefix( - prefix, aFillSequenceGaps ); - - if( !newReference.IsEmpty() ) - { - SetReference( newReference ); - success = true; - } - - return success; -} - - double MODULE::PadCoverageRatio() const { double padArea = 0.0; diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index dd1e5efe10..2034dce396 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -450,25 +450,6 @@ public: TEXTE_MODULE& Value() const { return *m_Value; } TEXTE_MODULE& Reference() const { return *m_Reference; } - /*! - * Function IncrementItemReference - * Implementation of the generic "reference" incrementing interface - * Increments the numeric suffix, filling any sequence gaps - */ - bool IncrementItemReference(); //override - - /** - * Function IncrementReference - * Increments the module's reference, if possible. A reference with - * a numerical suffix and an optional alphabetical prefix can be - * incremented: "A1" and "1" can be, "B" can't. - * - * @param aFillSequenceGaps if true, the next reference in a sequence - * like A1,A3,A4 will be A2. If false, it will be A5. - * @return true if the reference was incremented. - */ - bool IncrementReference( bool aFillSequenceGaps ); - /** * Function FindPadByName * returns a D_PAD* with a matching name. Note that names may not be diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index 89ebfb1ab9..b638e078f0 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -413,13 +413,6 @@ void D_PAD::SetPadName( const wxString& name ) } -bool D_PAD::IncrementItemReference() -{ - // Take the next available pad number - return IncrementPadName( true, true ); -} - - bool D_PAD::IncrementPadName( bool aSkipUnconnectable, bool aFillSequenceGaps ) { bool skip = aSkipUnconnectable && ( GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED ); diff --git a/pcbnew/class_pad.h b/pcbnew/class_pad.h index 5aa2d14ef4..03e59483fc 100644 --- a/pcbnew/class_pad.h +++ b/pcbnew/class_pad.h @@ -132,20 +132,14 @@ public: */ const wxUint32 GetPackedPadName() const { return m_NumPadName; } - /*! - * Function IncrementItemReference - * Implementation of the generic "reference" incrementing interface - * Increments the numeric suffix, filling any sequence gaps and skipping - * pads that aren't connectable - */ - bool IncrementItemReference(); // override - /** * Function IncrementPadName * * Increments the pad name to the next available name in the module. * * @param aSkipUnconnectable skips any pads that are not connectable (for example NPTH) + * @param aFillSequenceGaps if true, the next reference in a sequence + * like A1,A3,A4 will be A2. If false, it will be A5. * @return pad name incremented */ bool IncrementPadName( bool aSkipUnconnectable, bool aFillSequenceGaps ); diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index 15332ac5e6..d9cc1cbd6a 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -127,16 +127,16 @@ protected: * This function is shared between pcbnew and modedit, as it is virtually * the same * @param aItem the item to duplicate - * @aIncrement increment item reference (module ref, pad number, etc, - * if appropriate) + * @param aIncrement (has meaning only for pads in footprint editor): + * increment pad name if appropriate */ void duplicateItem( BOARD_ITEM* aItem, bool aIncrement ); /** * Function duplicateItems * Find and duplicate the currently selected items - * @param aIncrement increment item reference (module ref, pad number, etc, - * if appropriate) + * @param aIncrement (has meaning only for pads in footprint editor): + * increment pad name if appropriate * * @note The implementer should find the selected item (and do processing * like finding parents when relevant, and then call diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index c9df5c025c..4bf4ba1833 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -756,7 +756,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, increment ); + new_item = editFrame->GetBoard()->DuplicateAndAddItem( item ); } if( new_item )