Commit 5941f196 authored by Maciej Suminski's avatar Maciej Suminski

Reference point is selected for copied items. Enabled autopanning for copy &...

Reference point is selected for copied items. Enabled autopanning for copy & paste operations (module editor/GAL).
parent 95a4f61e
...@@ -434,7 +434,6 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent ) ...@@ -434,7 +434,6 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent )
int EDIT_TOOL::CopyItems( TOOL_EVENT& aEvent ) int EDIT_TOOL::CopyItems( TOOL_EVENT& aEvent )
{ {
const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection(); const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection();
PCB_IO io( CTL_FOR_CLIPBOARD );
if( !m_editModules || !makeSelection( selection ) ) if( !m_editModules || !makeSelection( selection ) )
{ {
...@@ -443,6 +442,40 @@ int EDIT_TOOL::CopyItems( TOOL_EVENT& aEvent ) ...@@ -443,6 +442,40 @@ int EDIT_TOOL::CopyItems( TOOL_EVENT& aEvent )
return 0; return 0;
} }
Activate();
KIGFX::VIEW_CONTROLS* controls = getViewControls();
controls->SetSnapping( true );
controls->ShowCursor( true );
controls->SetAutoPan( true );
PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>();
frame->DisplayToolMsg( _( "Select reference point" ) );
bool cancelled = false;
VECTOR2I cursorPos;
while( OPT_TOOL_EVENT evt = Wait() )
{
if( evt->IsMotion() )
{
cursorPos = getViewControls()->GetCursorPosition();
}
else if( evt->IsClick( BUT_LEFT ) )
{
break;
}
else if( evt->IsCancel() || evt->IsActivate() )
{
cancelled = true;
break;
}
}
if( !cancelled )
{
PCB_IO io( CTL_FOR_CLIPBOARD );
// Create a temporary module that contains selected items to ease serialization // Create a temporary module that contains selected items to ease serialization
MODULE module( getModel<BOARD>() ); MODULE module( getModel<BOARD>() );
...@@ -457,9 +490,19 @@ int EDIT_TOOL::CopyItems( TOOL_EVENT& aEvent ) ...@@ -457,9 +490,19 @@ int EDIT_TOOL::CopyItems( TOOL_EVENT& aEvent )
module.Add( clone ); module.Add( clone );
} }
// Set the new relative internal local coordinates of footprint items
wxPoint moveVector = module.GetPosition() - wxPoint( cursorPos.x, cursorPos.y );
module.MoveAnchorPosition( moveVector );
io.Format( &module, 0 ); io.Format( &module, 0 );
std::string data = io.GetStringOutput( true ); std::string data = io.GetStringOutput( true );
m_toolMgr->SaveClipboard( data ); m_toolMgr->SaveClipboard( data );
}
frame->DisplayToolMsg( wxString::Format( _( "Copied %d items" ), selection.Size() ) );
controls->SetSnapping( false );
controls->ShowCursor( false );
controls->SetAutoPan( false );
setTransitions(); setTransitions();
...@@ -504,6 +547,7 @@ int EDIT_TOOL::PasteItems( TOOL_EVENT& aEvent ) ...@@ -504,6 +547,7 @@ int EDIT_TOOL::PasteItems( TOOL_EVENT& aEvent )
// Add a VIEW_GROUP that serves as a preview for the new item // Add a VIEW_GROUP that serves as a preview for the new item
KIGFX::VIEW_GROUP preview( view ); KIGFX::VIEW_GROUP preview( view );
pastedModule->SetParent( board ); pastedModule->SetParent( board );
pastedModule->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
pastedModule->RunOnChildren( boost::bind( &KIGFX::VIEW_GROUP::Add, boost::ref( preview ), _1 ) ); pastedModule->RunOnChildren( boost::bind( &KIGFX::VIEW_GROUP::Add, boost::ref( preview ), _1 ) );
preview.Add( pastedModule ); preview.Add( pastedModule );
view->Add( &preview ); view->Add( &preview );
...@@ -511,6 +555,7 @@ int EDIT_TOOL::PasteItems( TOOL_EVENT& aEvent ) ...@@ -511,6 +555,7 @@ int EDIT_TOOL::PasteItems( TOOL_EVENT& aEvent )
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
controls->ShowCursor( true ); controls->ShowCursor( true );
controls->SetSnapping( true ); controls->SetSnapping( true );
controls->SetAutoPan( true );
Activate(); Activate();
...@@ -558,6 +603,7 @@ int EDIT_TOOL::PasteItems( TOOL_EVENT& aEvent ) ...@@ -558,6 +603,7 @@ int EDIT_TOOL::PasteItems( TOOL_EVENT& aEvent )
for( D_PAD* pad = pastedModule->Pads(); pad; pad = pad->Next() ) for( D_PAD* pad = pastedModule->Pads(); pad; pad = pad->Next() )
{ {
D_PAD* clone = static_cast<D_PAD*>( pad->Clone() ); D_PAD* clone = static_cast<D_PAD*>( pad->Clone() );
currentModule->Add( clone ); currentModule->Add( clone );
clone->SetLocalCoord(); clone->SetLocalCoord();
view->Add( clone ); view->Add( clone );
......
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