Commit ae431bbb authored by Maciej Suminski's avatar Maciej Suminski

Added MODULE::Add( BOARD_ITEM* )/Remove( BOARD_ITEM* )/Delete( BOARD_ITEM* ).

Removed MODULE::AddPad().
parent 456eeaba
...@@ -295,6 +295,72 @@ void MODULE::Copy( MODULE* aModule ) ...@@ -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<TEXTE_MODULE*>( aBoardItem )->GetType() == TEXTE_MODULE::TEXT_is_DIVERS );
/* no break */
case PCB_MODULE_EDGE_T:
if( doAppend )
m_Drawings.PushBack( static_cast<BOARD_ITEM*>( aBoardItem ) );
else
m_Drawings.PushFront( static_cast<BOARD_ITEM*>( aBoardItem ) );
break;
case PCB_PAD_T:
if( doAppend )
m_Pads.PushBack( static_cast<D_PAD*>( aBoardItem ) );
else
m_Pads.PushFront( static_cast<D_PAD*>( 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<TEXTE_MODULE*>( aBoardItem )->GetType() == TEXTE_MODULE::TEXT_is_DIVERS );
/* no break */
case PCB_MODULE_EDGE_T:
return m_Drawings.Remove( static_cast<BOARD_ITEM*>( aBoardItem ) );
case PCB_PAD_T:
return m_Pads.Remove( static_cast<D_PAD*>( 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 ) void MODULE::CopyNetlistSettings( MODULE* aModule )
{ {
// Don't do anything foolish like trying to copy to yourself. // Don't do anything foolish like trying to copy to yourself.
...@@ -636,13 +702,6 @@ void MODULE::Add3DModel( S3D_MASTER* a3DModel ) ...@@ -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 // see class_module.h
SEARCH_RESULT MODULE::Visit( INSPECTOR* inspector, const void* testData, SEARCH_RESULT MODULE::Visit( INSPECTOR* inspector, const void* testData,
const KICAD_T scanTypes[] ) const KICAD_T scanTypes[] )
...@@ -738,10 +797,10 @@ EDA_ITEM* MODULE::Clone() const ...@@ -738,10 +797,10 @@ EDA_ITEM* MODULE::Clone() const
void MODULE::RunOnChildren( boost::function<void (BOARD_ITEM*)> aFunction ) void MODULE::RunOnChildren( boost::function<void (BOARD_ITEM*)> 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<BOARD_ITEM*>( pad ) ); aFunction( static_cast<BOARD_ITEM*>( 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( drawing );
aFunction( static_cast<BOARD_ITEM*>( m_Reference ) ); aFunction( static_cast<BOARD_ITEM*>( m_Reference ) );
......
...@@ -91,9 +91,31 @@ public: ...@@ -91,9 +91,31 @@ public:
* Function Add * Function Add
* adds the given item to this MODULE and takes ownership of its memory. * adds the given item to this MODULE and takes ownership of its memory.
* @param aBoardItem The item to add to this board. * @param aBoardItem The item to add to this board.
* @param doInsert If true, then insert, else append * @param doAppend If true, then append, else insert.
* void Add( BOARD_ITEM* aBoardItem, bool doInsert = true );
*/ */
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 * Function CalculateBoundingBox
...@@ -436,14 +458,6 @@ public: ...@@ -436,14 +458,6 @@ public:
*/ */
void Add3DModel( S3D_MASTER* a3DModel ); 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, SEARCH_RESULT Visit( INSPECTOR* inspector, const void* testData,
const KICAD_T scanTypes[] ); const KICAD_T scanTypes[] );
......
...@@ -637,7 +637,7 @@ MODULE* GPCB_FPL_CACHE::parseMODULE( LINE_READER* aLineReader ) throw( IO_ERROR, ...@@ -637,7 +637,7 @@ MODULE* GPCB_FPL_CACHE::parseMODULE( LINE_READER* aLineReader ) throw( IO_ERROR,
pad->SetShape( PAD_OVAL ); pad->SetShape( PAD_OVAL );
} }
module->AddPad( pad ); module->Add( pad );
continue; continue;
} }
...@@ -701,7 +701,7 @@ MODULE* GPCB_FPL_CACHE::parseMODULE( LINE_READER* aLineReader ) throw( IO_ERROR, ...@@ -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 ) if( pad->GetShape() == PAD_ROUND && pad->GetSize().x != pad->GetSize().y )
pad->SetShape( PAD_OVAL ); pad->SetShape( PAD_OVAL );
module->AddPad( pad ); module->Add( pad );
continue; continue;
} }
} }
......
...@@ -1856,7 +1856,7 @@ MODULE* PCB_PARSER::parseMODULE( wxArrayString* aInitialComments ) throw( IO_ERR ...@@ -1856,7 +1856,7 @@ MODULE* PCB_PARSER::parseMODULE( wxArrayString* aInitialComments ) throw( IO_ERR
RotatePoint( &pt, module->GetOrientation() ); RotatePoint( &pt, module->GetOrientation() );
pad->SetPosition( pt + module->GetPosition() ); pad->SetPosition( pt + module->GetPosition() );
module->AddPad( pad ); module->Add( pad );
} }
break; break;
......
...@@ -464,6 +464,9 @@ void EDIT_TOOL::remove( BOARD_ITEM* aItem ) ...@@ -464,6 +464,9 @@ void EDIT_TOOL::remove( BOARD_ITEM* aItem )
case TEXTE_MODULE::TEXT_is_VALUE: case TEXTE_MODULE::TEXT_is_VALUE:
DisplayError( getEditFrame<PCB_BASE_FRAME>(), _( "Cannot delete VALUE!" ) ); DisplayError( getEditFrame<PCB_BASE_FRAME>(), _( "Cannot delete VALUE!" ) );
return; return;
default: // suppress warnings
break;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment