Fix a few issues when copying a footprint from fp editor to clipboard, and paste it:

- ref and value texts were converted to user texts.
- fpid was left empty, thus creating a potential issue if pasted in the board editor.
Now:
- ref and value texts are no changed, and not copied is pasted in the footprint editor
(these texts already exist)
- a dummy fpid (clipboard:<md5 string>) is added if pasted in board editor
(Pasting a (partial) footprint from fp editor to a board editor is certainly not
a good idea but is possible)
This commit is contained in:
jean-pierre charras 2020-11-25 17:09:23 +01:00
parent 68625494f3
commit 5c08ad1ab9
2 changed files with 14 additions and 38 deletions

View File

@ -100,6 +100,13 @@ void CLIPBOARD_IO::SaveSelection( const PCBNEW_SELECTION& aSelected, bool isFoot
{
FOOTPRINT partialFootprint( m_board );
// Usefull to copy the selection to the board editor (if any), and provides
// a dummy lib id.
// Perhaps not a good Id, but better than a empty id
KIID dummy;
LIB_ID id( "clipboard", dummy.AsString() );
partialFootprint.SetFPID( id );
for( const EDA_ITEM* item : aSelected )
{
const PCB_GROUP* group = dynamic_cast<const PCB_GROUP*>( item );
@ -110,10 +117,6 @@ void CLIPBOARD_IO::SaveSelection( const PCBNEW_SELECTION& aSelected, bool isFoot
else
clone = static_cast<BOARD_ITEM*>( item->Clone() );
// Do not add reference/value - convert them to the common type
if( FP_TEXT* text = dyn_cast<FP_TEXT*>( clone ) )
text->SetType( FP_TEXT::TEXT_is_DIVERS );
// If it is only a footprint, clear the nets from the pads
if( PAD* pad = dyn_cast<PAD*>( clone ) )
pad->SetNetCode( 0 );

View File

@ -539,8 +539,8 @@ int PCBNEW_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent )
}
void pasteFootprintItemsToFootprintEditor( FOOTPRINT* aClipFootprint, BOARD* aBoard,
std::vector<BOARD_ITEM*>& aPastedItems )
static void pasteFootprintItemsToFootprintEditor( FOOTPRINT* aClipFootprint, BOARD* aBoard,
std::vector<BOARD_ITEM*>& aPastedItems )
{
FOOTPRINT* editorFootprint = aBoard->GetFirstFootprint();
@ -554,6 +554,10 @@ void pasteFootprintItemsToFootprintEditor( FOOTPRINT* aClipFootprint, BOARD* aBo
aClipFootprint->Pads().clear();
// Not all graphic items can be added to the current footprint:
// Reference and value are already existing in the current footprint, and
// must be unique.
// So they will be skipped
for( BOARD_ITEM* item : aClipFootprint->GraphicalItems() )
{
if( item->Type() == PCB_FP_SHAPE_T )
@ -568,12 +572,7 @@ void pasteFootprintItemsToFootprintEditor( FOOTPRINT* aClipFootprint, BOARD* aBo
FP_TEXT* text = static_cast<FP_TEXT*>( item );
if( text->GetType() != FP_TEXT::TEXT_is_DIVERS )
text->SetType( FP_TEXT::TEXT_is_DIVERS );
if( text->GetText() == "${VALUE}" )
text->SetText( aClipFootprint->GetValue() );
else if( text->GetText() == "${REFERENCE}" )
text->SetText( aClipFootprint->GetReference() );
continue;
text->SetTextAngle( aClipFootprint->GetOrientation() );
@ -594,32 +593,6 @@ void pasteFootprintItemsToFootprintEditor( FOOTPRINT* aClipFootprint, BOARD* aBo
}
aClipFootprint->Groups().clear();
if( !aClipFootprint->GetReference().IsEmpty() )
{
FP_TEXT* text = new FP_TEXT( aClipFootprint->Reference() );
text->SetType( FP_TEXT::TEXT_is_DIVERS );
text->SetTextAngle( aClipFootprint->GetOrientation() );
text->SetParent( nullptr );
text->SetLocalCoord();
text->SetParent( editorFootprint );
aPastedItems.push_back( text );
}
if( !aClipFootprint->GetValue().IsEmpty() )
{
FP_TEXT* text = new FP_TEXT( aClipFootprint->Value() );
text->SetType( FP_TEXT::TEXT_is_DIVERS );
text->SetTextAngle( aClipFootprint->GetOrientation() );
text->SetParent( nullptr );
text->SetLocalCoord();
text->SetParent( editorFootprint );
aPastedItems.push_back( text );
}
}