Make 'Enumerate Pad' tool more user friendly
Effects of enumeration are shown instantly, instead of after accepting the changes.
This commit is contained in:
parent
1d8730752c
commit
a5ac165c4b
|
@ -206,12 +206,11 @@ int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent )
|
int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
std::list<D_PAD*> pads;
|
|
||||||
std::set<D_PAD*> allPads;
|
|
||||||
|
|
||||||
if( !m_board->m_Modules || !m_board->m_Modules->Pads() )
|
if( !m_board->m_Modules || !m_board->m_Modules->Pads() )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
Activate();
|
||||||
|
|
||||||
GENERAL_COLLECTOR collector;
|
GENERAL_COLLECTOR collector;
|
||||||
const KICAD_T types[] = { PCB_PAD_T, EOT };
|
const KICAD_T types[] = { PCB_PAD_T, EOT };
|
||||||
|
|
||||||
|
@ -222,10 +221,6 @@ int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent )
|
||||||
guide.SetIgnoreModulesVals( true );
|
guide.SetIgnoreModulesVals( true );
|
||||||
guide.SetIgnoreModulesRefs( true );
|
guide.SetIgnoreModulesRefs( true );
|
||||||
|
|
||||||
// Create a set containing all pads (to avoid double adding to the list)
|
|
||||||
for( D_PAD* p = m_board->m_Modules->Pads(); p; p = p->Next() )
|
|
||||||
allPads.insert( p );
|
|
||||||
|
|
||||||
DIALOG_ENUM_PADS settingsDlg( m_frame );
|
DIALOG_ENUM_PADS settingsDlg( m_frame );
|
||||||
|
|
||||||
if( settingsDlg.ShowModal() == wxID_CANCEL )
|
if( settingsDlg.ShowModal() == wxID_CANCEL )
|
||||||
|
@ -236,12 +231,14 @@ int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
m_frame->DisplayToolMsg( _( "Hold left mouse button and move cursor over pads to enumerate them" ) );
|
m_frame->DisplayToolMsg( _( "Hold left mouse button and move cursor over pads to enumerate them" ) );
|
||||||
|
|
||||||
Activate();
|
|
||||||
|
|
||||||
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
||||||
m_controls->ShowCursor( true );
|
m_controls->ShowCursor( true );
|
||||||
|
|
||||||
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
||||||
VECTOR2I oldCursorPos = m_controls->GetCursorPosition();
|
VECTOR2I oldCursorPos = m_controls->GetCursorPosition();
|
||||||
std::list<D_PAD*> selectedPads;
|
std::list<D_PAD*> selectedPads;
|
||||||
|
BOARD_COMMIT commit( m_frame );
|
||||||
|
std::map<wxString, wxString> oldNames;
|
||||||
|
|
||||||
while( OPT_TOOL_EVENT evt = Wait() )
|
while( OPT_TOOL_EVENT evt = Wait() )
|
||||||
{
|
{
|
||||||
|
@ -290,22 +287,33 @@ int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
for( D_PAD* pad : selectedPads )
|
for( D_PAD* pad : selectedPads )
|
||||||
{
|
{
|
||||||
std::set<D_PAD*>::iterator it = allPads.find( pad );
|
// If pad was not selected, then enumerate it
|
||||||
|
if( !pad->IsSelected() )
|
||||||
// Add the pad to the list, if it was not selected previously..
|
|
||||||
if( it != allPads.end() )
|
|
||||||
{
|
{
|
||||||
allPads.erase( it );
|
commit.Modify( pad );
|
||||||
pads.push_back( pad );
|
|
||||||
|
// Rename pad and store the old name
|
||||||
|
wxString newName = wxString::Format( wxT( "%s%d" ), padPrefix.c_str(), padNumber++ );
|
||||||
|
oldNames[newName] = pad->GetPadName();
|
||||||
|
pad->SetPadName( newName );
|
||||||
pad->SetSelected();
|
pad->SetSelected();
|
||||||
|
getView()->Update( pad );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ..or remove it from the list if it was clicked
|
// ..or restore the old name if it was enumerated and clicked again
|
||||||
else if( evt->IsClick( BUT_LEFT ) )
|
else if( pad->IsSelected() && evt->IsClick( BUT_LEFT ) )
|
||||||
{
|
{
|
||||||
allPads.insert( pad );
|
auto it = oldNames.find( pad->GetPadName() );
|
||||||
pads.remove( pad );
|
wxASSERT( it != oldNames.end() );
|
||||||
|
|
||||||
|
if( it != oldNames.end() )
|
||||||
|
{
|
||||||
|
pad->SetPadName( it->second );
|
||||||
|
oldNames.erase( it );
|
||||||
|
}
|
||||||
|
|
||||||
pad->ClearSelected();
|
pad->ClearSelected();
|
||||||
|
getView()->Update( pad );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,29 +323,22 @@ int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent )
|
||||||
else if( ( evt->IsKeyPressed() && evt->KeyCode() == WXK_RETURN ) ||
|
else if( ( evt->IsKeyPressed() && evt->KeyCode() == WXK_RETURN ) ||
|
||||||
evt->IsDblClick( BUT_LEFT ) )
|
evt->IsDblClick( BUT_LEFT ) )
|
||||||
{
|
{
|
||||||
// Accept changes
|
|
||||||
BOARD_COMMIT commit( m_frame );
|
|
||||||
m_frame->OnModify();
|
|
||||||
|
|
||||||
for( D_PAD* pad : pads )
|
|
||||||
{
|
|
||||||
commit.Modify( pad );
|
|
||||||
pad->SetPadName( wxString::Format( wxT( "%s%d" ), padPrefix.c_str(), padNumber++ ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
commit.Push( _( "Enumerate pads" ) );
|
commit.Push( _( "Enumerate pads" ) );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if( evt->IsCancel() || evt->IsActivate() )
|
else if( evt->IsCancel() || evt->IsActivate() )
|
||||||
{
|
{
|
||||||
|
commit.Revert();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( D_PAD* pad : pads )
|
for( D_PAD* p = m_board->m_Modules->Pads(); p; p = p->Next() )
|
||||||
pad->ClearSelected();
|
{
|
||||||
|
p->ClearSelected();
|
||||||
|
view->Update( p );
|
||||||
|
}
|
||||||
|
|
||||||
m_frame->DisplayToolMsg( wxEmptyString );
|
m_frame->DisplayToolMsg( wxEmptyString );
|
||||||
m_controls->ShowCursor( false );
|
m_controls->ShowCursor( false );
|
||||||
|
|
Loading…
Reference in New Issue