diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index bc01aa1bcb..6080fa0d98 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -295,6 +295,72 @@ void MODULE::Copy( MODULE* aModule ) } +void MODULE::Add( BOARD_ITEM* aBoardItem, bool doAppend ) +{ + switch( aBoardItem->Type() ) + { + case PCB_MODULE_TEXT_T: + // Only common texts can be added this way. Reference and value are not hold in the DLIST. + assert( static_cast( aBoardItem )->GetType() == TEXTE_MODULE::TEXT_is_DIVERS ); + /* no break */ + + case PCB_MODULE_EDGE_T: + if( doAppend ) + m_Drawings.PushBack( static_cast( aBoardItem ) ); + else + m_Drawings.PushFront( static_cast( aBoardItem ) ); + break; + + case PCB_PAD_T: + if( doAppend ) + m_Pads.PushBack( static_cast( aBoardItem ) ); + else + m_Pads.PushFront( static_cast( aBoardItem ) ); + break; + + default: + { + wxString msg; + msg.Printf( wxT( "MODULE::Add() needs work: BOARD_ITEM type (%d) not handled" ), + aBoardItem->Type() ); + wxFAIL_MSG( msg ); + + return; + } + } + + aBoardItem->SetParent( this ); +} + + +BOARD_ITEM* MODULE::Remove( BOARD_ITEM* aBoardItem ) +{ + switch( aBoardItem->Type() ) + { + case PCB_MODULE_TEXT_T: + // Only common texts can be added this way. Reference and value are not hold in the DLIST. + assert( static_cast( aBoardItem )->GetType() == TEXTE_MODULE::TEXT_is_DIVERS ); + /* no break */ + + case PCB_MODULE_EDGE_T: + return m_Drawings.Remove( static_cast( aBoardItem ) ); + + case PCB_PAD_T: + return m_Pads.Remove( static_cast( aBoardItem ) ); + + default: + { + wxString msg; + msg.Printf( wxT( "MODULE::Remove() needs work: BOARD_ITEM type (%d) not handled" ), + aBoardItem->Type() ); + wxFAIL_MSG( msg ); + } + } + + return NULL; +} + + void MODULE::CopyNetlistSettings( MODULE* aModule ) { // Don't do anything foolish like trying to copy to yourself. @@ -636,13 +702,6 @@ void MODULE::Add3DModel( S3D_MASTER* a3DModel ) } -void MODULE::AddPad( D_PAD* aPad ) -{ - aPad->SetParent( this ); - m_Pads.PushBack( aPad ); -} - - // see class_module.h SEARCH_RESULT MODULE::Visit( INSPECTOR* inspector, const void* testData, const KICAD_T scanTypes[] ) @@ -738,10 +797,10 @@ EDA_ITEM* MODULE::Clone() const void MODULE::RunOnChildren( boost::function aFunction ) { - for( D_PAD* pad = m_Pads.GetFirst(); pad; pad = pad->Next() ) + for( D_PAD* pad = m_Pads; pad; pad = pad->Next() ) aFunction( static_cast( pad ) ); - for( BOARD_ITEM* drawing = m_Drawings.GetFirst(); drawing; drawing = drawing->Next() ) + for( BOARD_ITEM* drawing = m_Drawings; drawing; drawing = drawing->Next() ) aFunction( drawing ); aFunction( static_cast( m_Reference ) ); diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index 8eac8a87d8..d1496f2425 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -91,9 +91,31 @@ public: * 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 doInsert If true, then insert, else append - * void Add( BOARD_ITEM* aBoardItem, bool doInsert = true ); + * @param doAppend If true, then append, else insert. */ + void Add( BOARD_ITEM* aBoardItem, bool doAppend = true ); + + /** + * 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 ); /** * Function CalculateBoundingBox @@ -436,14 +458,6 @@ public: */ void Add3DModel( S3D_MASTER* a3DModel ); - /** - * Function AddPad - * adds \a aPad to the end of the pad list. - * - * @param aPad A pointer to a #D_PAD to add to the list. - */ - void AddPad( D_PAD* aPad ); - SEARCH_RESULT Visit( INSPECTOR* inspector, const void* testData, const KICAD_T scanTypes[] ); diff --git a/pcbnew/gpcb_plugin.cpp b/pcbnew/gpcb_plugin.cpp index def86f32ff..c306aa8639 100644 --- a/pcbnew/gpcb_plugin.cpp +++ b/pcbnew/gpcb_plugin.cpp @@ -637,7 +637,7 @@ MODULE* GPCB_FPL_CACHE::parseMODULE( LINE_READER* aLineReader ) throw( IO_ERROR, pad->SetShape( PAD_OVAL ); } - module->AddPad( pad ); + module->Add( pad ); continue; } @@ -701,7 +701,7 @@ MODULE* GPCB_FPL_CACHE::parseMODULE( LINE_READER* aLineReader ) throw( IO_ERROR, if( pad->GetShape() == PAD_ROUND && pad->GetSize().x != pad->GetSize().y ) pad->SetShape( PAD_OVAL ); - module->AddPad( pad ); + module->Add( pad ); continue; } } diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index 475a844948..33783ea548 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -1856,7 +1856,7 @@ MODULE* PCB_PARSER::parseMODULE( wxArrayString* aInitialComments ) throw( IO_ERR RotatePoint( &pt, module->GetOrientation() ); pad->SetPosition( pt + module->GetPosition() ); - module->AddPad( pad ); + module->Add( pad ); } break; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index e4667867c3..c1bbcc14a9 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -464,6 +464,9 @@ void EDIT_TOOL::remove( BOARD_ITEM* aItem ) case TEXTE_MODULE::TEXT_is_VALUE: DisplayError( getEditFrame(), _( "Cannot delete VALUE!" ) ); return; + + default: // suppress warnings + break; } } }