Another attempt to fix offset issues when pasting board items to ModEdit.
Fixes https://gitlab.com/kicad/code/kicad/issues/4032
This commit is contained in:
parent
53dfcd84cb
commit
3b97993daf
|
@ -80,11 +80,10 @@ public:
|
|||
|
||||
/**
|
||||
* Flip entity relative to aCentre.
|
||||
* The item is mirrored, and layer changed to the paired corresponding layer
|
||||
* if it is on a paired layer
|
||||
* This function should be called only from MODULE::Flip because there is
|
||||
* not usual to flip an item alone, without flipping the parent footprint.
|
||||
* (consider Mirror for a mirror transform).
|
||||
* The item is mirrored, and layer changed to the paired corresponding layer if it is on
|
||||
* a paired layer.
|
||||
* This function should be called only from MODULE::Flip because it is not usual to flip
|
||||
* an item alone, without flipping the parent footprint (consider Mirror() instead).
|
||||
*/
|
||||
void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
|
||||
|
||||
|
@ -104,16 +103,14 @@ public:
|
|||
|
||||
/**
|
||||
* Set relative coordinates from draw coordinates.
|
||||
* Call in only when the geometry ov the footprint is modified
|
||||
* and therefore the relative coordinates have to be updated from
|
||||
* the draw coordinates
|
||||
* Call in only when the geometry or the footprint is modified and therefore the relative
|
||||
* coordinates have to be updated from the draw coordinates.
|
||||
*/
|
||||
void SetLocalCoord();
|
||||
|
||||
/**
|
||||
* Set draw coordinates (absolute values ) from relative coordinates.
|
||||
* Must be called when a relative coordinate has changed, in order
|
||||
* to see the changes on screen
|
||||
* Must be called when a relative coordinate has changed in order to see the changes on screen
|
||||
*/
|
||||
void SetDrawCoord();
|
||||
|
||||
|
|
|
@ -620,6 +620,82 @@ int PCBNEW_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent )
|
|||
}
|
||||
|
||||
|
||||
void pasteModuleItemsToModEdit( MODULE* aClipModule, BOARD* aBoard,
|
||||
std::vector<BOARD_ITEM*>& aPastedItems )
|
||||
{
|
||||
MODULE* editModule = aBoard->GetFirstModule();
|
||||
|
||||
aClipModule->SetParent( aBoard );
|
||||
|
||||
for( D_PAD* pad : aClipModule->Pads() )
|
||||
{
|
||||
pad->SetParent( editModule );
|
||||
aPastedItems.push_back( pad );
|
||||
}
|
||||
|
||||
aClipModule->Pads().clear();
|
||||
|
||||
for( BOARD_ITEM* item : aClipModule->GraphicalItems() )
|
||||
{
|
||||
if( item->Type() == PCB_MODULE_EDGE_T )
|
||||
{
|
||||
EDGE_MODULE* edge = static_cast<EDGE_MODULE*>( item );
|
||||
|
||||
edge->SetParent( nullptr );
|
||||
edge->SetLocalCoord();
|
||||
}
|
||||
else if( item->Type() == PCB_MODULE_TEXT_T )
|
||||
{
|
||||
TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
|
||||
|
||||
if( text->GetType() != TEXTE_MODULE::TEXT_is_DIVERS )
|
||||
text->SetType( TEXTE_MODULE::TEXT_is_DIVERS );
|
||||
|
||||
if( text->GetText() == "%V" )
|
||||
text->SetText( aClipModule->GetValue() );
|
||||
else if( text->GetText() == "%R" )
|
||||
text->SetText( aClipModule->GetReference() );
|
||||
|
||||
text->SetTextAngle( aClipModule->GetOrientation() );
|
||||
|
||||
text->SetParent( nullptr );
|
||||
text->SetLocalCoord();
|
||||
}
|
||||
|
||||
item->SetParent( editModule );
|
||||
aPastedItems.push_back( item );
|
||||
}
|
||||
|
||||
aClipModule->GraphicalItems().clear();
|
||||
|
||||
if( !aClipModule->GetReference().IsEmpty() )
|
||||
{
|
||||
TEXTE_MODULE* text = new TEXTE_MODULE( aClipModule->Reference() );
|
||||
text->SetType( TEXTE_MODULE::TEXT_is_DIVERS );
|
||||
text->SetTextAngle( aClipModule->GetOrientation() );
|
||||
|
||||
text->SetParent( nullptr );
|
||||
text->SetLocalCoord();
|
||||
|
||||
text->SetParent( editModule );
|
||||
aPastedItems.push_back( text );
|
||||
}
|
||||
|
||||
if( !aClipModule->GetValue().IsEmpty() )
|
||||
{
|
||||
TEXTE_MODULE* text = new TEXTE_MODULE( aClipModule->Value() );
|
||||
text->SetType( TEXTE_MODULE::TEXT_is_DIVERS );
|
||||
text->SetTextAngle( aClipModule->GetOrientation() );
|
||||
|
||||
text->SetParent( nullptr );
|
||||
text->SetLocalCoord();
|
||||
|
||||
text->SetParent( editModule );
|
||||
aPastedItems.push_back( text );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int PCBNEW_CONTROL::Paste( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
CLIPBOARD_IO pi;
|
||||
|
@ -662,26 +738,7 @@ int PCBNEW_CONTROL::Paste( const TOOL_EVENT& aEvent )
|
|||
std::vector<BOARD_ITEM*> pastedItems;
|
||||
|
||||
for( MODULE* clipModule : clipBoard->Modules() )
|
||||
{
|
||||
clipModule->SetParent( board() );
|
||||
|
||||
for( auto pad : clipModule->Pads() )
|
||||
{
|
||||
pad->SetParent( editModule );
|
||||
pastedItems.push_back( pad );
|
||||
}
|
||||
|
||||
clipModule->Pads().clear();
|
||||
|
||||
for( auto item : clipModule->GraphicalItems() )
|
||||
{
|
||||
item->Move( clipModule->GetPosition() );
|
||||
item->SetParent( editModule );
|
||||
pastedItems.push_back( item );
|
||||
}
|
||||
|
||||
clipModule->GraphicalItems().clear();
|
||||
}
|
||||
pasteModuleItemsToModEdit( clipModule, board(), pastedItems );
|
||||
|
||||
for( BOARD_ITEM* clipDrawItem : clipBoard->Drawings() )
|
||||
{
|
||||
|
@ -731,24 +788,7 @@ int PCBNEW_CONTROL::Paste( const TOOL_EVENT& aEvent )
|
|||
|
||||
if( editModules )
|
||||
{
|
||||
MODULE* editModule = board()->GetFirstModule();
|
||||
|
||||
for( auto pad : clipModule->Pads() )
|
||||
{
|
||||
pad->SetParent( editModule );
|
||||
pastedItems.push_back( pad );
|
||||
}
|
||||
|
||||
clipModule->Pads().clear();
|
||||
|
||||
for( auto item : clipModule->GraphicalItems() )
|
||||
{
|
||||
item->SetParent( editModule );
|
||||
pastedItems.push_back( item );
|
||||
}
|
||||
|
||||
clipModule->GraphicalItems().clear();
|
||||
|
||||
pasteModuleItemsToModEdit( clipModule, board(), pastedItems );
|
||||
delete clipModule;
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue