Make sure router and via tools update when sizes change.

Also adds a size menu to the context menu for the Via tool.

Fixes https://gitlab.com/kicad/code/kicad/issues/5321
This commit is contained in:
Jeff Young 2020-08-31 23:32:11 +01:00
parent 2979d709f3
commit 6e72f609f0
4 changed files with 109 additions and 20 deletions

View File

@ -24,27 +24,21 @@
#include <sch_line_wire_bus_tool.h>
#include <boost/optional/optional.hpp>
#include <wx/debug.h>
#include <wx/gdicmn.h>
#include <wx/menu.h>
#include <wx/string.h>
#include <wx/stringimpl.h>
#include <wx/translation.h>
#include <algorithm>
#include <cstdlib>
#include <deque>
#include <iterator>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <base_screen.h>
#include <base_struct.h>
#include <bitmaps.h>
#include <core/typeinfo.h>
#include <eda_text.h>
#include <layers_id_colors_and_visibility.h>
#include <math/vector2d.h>
#include <advanced_config.h>
@ -52,28 +46,20 @@
#include <tool/conditional_menu.h>
#include <tool/selection.h>
#include <tool/selection_conditions.h>
#include <tool/tool_action.h>
#include <tool/tool_event.h>
#include <tool/tool_interactive.h>
#include <tool/tool_manager.h>
#include <trigo.h>
#include <undo_redo_container.h>
#include <view/view_controls.h>
#include <connection_graph.h>
#include <eeschema_id.h>
#include <general.h>
#include <sch_bus_entry.h>
#include <sch_connection.h>
#include <sch_draw_panel.h>
#include <sch_edit_frame.h>
#include <sch_item.h>
#include <sch_line.h>
#include <sch_screen.h>
#include <sch_sheet.h>
#include <sch_sheet_path.h>
#include <sch_text.h>
#include <sch_view.h>
#include <schematic.h>
#include <ee_actions.h>

View File

@ -27,7 +27,8 @@
#include <pcbnew_id.h>
#include <board_design_settings.h>
#include <class_track.h>
#include <tools/pcb_actions.h>
#include <tool/tool_manager.h>
void PCB_EDIT_FRAME::SetTrackSegmentWidth( TRACK* aTrackItem,
PICKED_ITEMS_LIST* aItemsListPicker,
@ -225,4 +226,6 @@ void PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event( wxCommandEvent& event )
default:
break;
}
m_toolManager->RunAction( PCB_ACTIONS::trackViaSizeChanged, true );
}

View File

@ -55,10 +55,93 @@
#include <tools/selection_tool.h>
#include <tools/tool_event_utils.h>
#include <tools/zone_create_helper.h>
#include <pcbnew_id.h>
#include <dialogs/dialog_track_via_size.h>
using SCOPED_DRAW_MODE = SCOPED_SET_RESET<DRAWING_TOOL::MODE>;
class VIA_SIZE_MENU : public ACTION_MENU
{
public:
VIA_SIZE_MENU() :
ACTION_MENU( true )
{
SetIcon( width_track_via_xpm );
SetTitle( _( "Select Via Size" ) );
}
protected:
ACTION_MENU* create() const override
{
return new VIA_SIZE_MENU();
}
void update() override
{
PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) getToolManager()->GetToolHolder();
EDA_UNITS units = frame->GetUserUnits();
BOARD_DESIGN_SETTINGS& bds = frame->GetBoard()->GetDesignSettings();
bool useIndex = !bds.m_UseConnectedTrackWidth
&& !bds.UseCustomTrackViaSize();
wxString msg;
Clear();
Append( ID_POPUP_PCB_SELECT_CUSTOM_WIDTH, _( "Use Custom Values..." ),
_( "Specify custom track and via sizes" ), wxITEM_CHECK );
Check( ID_POPUP_PCB_SELECT_CUSTOM_WIDTH, bds.UseCustomTrackViaSize() );
AppendSeparator();
for( unsigned i = 1; i < bds.m_ViasDimensionsList.size(); i++ )
{
VIA_DIMENSION via = bds.m_ViasDimensionsList[i];
if( via.m_Drill > 0 )
msg.Printf( _("Via %s, drill %s" ),
MessageTextFromValue( units, via.m_Diameter, true ),
MessageTextFromValue( units, via.m_Drill, true ) );
else
msg.Printf( _( "Via %s" ), MessageTextFromValue( units, via.m_Diameter, true ) );
int menuIdx = ID_POPUP_PCB_SELECT_VIASIZE1 + i;
Append( menuIdx, msg, wxEmptyString, wxITEM_CHECK );
Check( menuIdx, useIndex && bds.GetViaSizeIndex() == i );
}
}
OPT_TOOL_EVENT eventHandler( const wxMenuEvent& aEvent ) override
{
PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) getToolManager()->GetToolHolder();
BOARD_DESIGN_SETTINGS& bds = frame->GetBoard()->GetDesignSettings();
int id = aEvent.GetId();
// On Windows, this handler can be called with an event ID not existing in any
// menuitem, so only set flags when we have an ID match.
if( id == ID_POPUP_PCB_SELECT_CUSTOM_WIDTH )
{
DIALOG_TRACK_VIA_SIZE sizeDlg( frame, bds );
if( sizeDlg.ShowModal() )
{
bds.UseCustomTrackViaSize( true );
bds.m_UseConnectedTrackWidth = false;
}
}
else if( id >= ID_POPUP_PCB_SELECT_VIASIZE1 && id <= ID_POPUP_PCB_SELECT_VIASIZE16 )
{
bds.UseCustomTrackViaSize( false );
bds.m_UseConnectedTrackWidth = false;
bds.SetViaSizeIndex( id - ID_POPUP_PCB_SELECT_VIASIZE1 );
}
return OPT_TOOL_EVENT( PCB_ACTIONS::trackViaSizeChanged.MakeEvent() );
}
};
DRAWING_TOOL::DRAWING_TOOL() :
PCB_TOOL_BASE( "pcbnew.InteractiveDrawing" ),
m_view( nullptr ), m_controls( nullptr ),
@ -75,13 +158,13 @@ DRAWING_TOOL::~DRAWING_TOOL()
bool DRAWING_TOOL::Init()
{
auto activeToolFunctor = [ this ] ( const SELECTION& aSel )
auto activeToolFunctor = [this]( const SELECTION& aSel )
{
return m_mode != MODE::NONE;
};
// some interactive drawing tools can undo the last point
auto canUndoPoint = [ this ] ( const SELECTION& aSel )
auto canUndoPoint = [this]( const SELECTION& aSel )
{
return ( m_mode == MODE::ARC
|| m_mode == MODE::ZONE
@ -90,13 +173,18 @@ bool DRAWING_TOOL::Init()
};
// functor for tools that can automatically close the outline
auto canCloseOutline = [ this ] ( const SELECTION& aSel )
auto canCloseOutline = [this]( const SELECTION& aSel )
{
return ( m_mode == MODE::ZONE
|| m_mode == MODE::KEEPOUT
|| m_mode == MODE::GRAPHIC_POLYGON );
};
auto viaToolActive = [this]( const SELECTION& aSel )
{
return m_mode == MODE::VIA;
};
auto& ctxMenu = m_menu.GetMenu();
// cancel current tool goes in main context menu at the top if present
@ -109,6 +197,13 @@ bool DRAWING_TOOL::Init()
ctxMenu.AddSeparator( 500 );
std::shared_ptr<VIA_SIZE_MENU> viaSizeMenu = std::make_shared<VIA_SIZE_MENU>();
viaSizeMenu->SetTool( this );
m_menu.AddSubMenu( viaSizeMenu );
ctxMenu.AddMenu( viaSizeMenu.get(), viaToolActive, 500 );
ctxMenu.AddSeparator( 500 );
// Type-specific sub-menus will be added for us by other tools
// For example, zone fill/unfill is provided by the PCB control tool

View File

@ -184,6 +184,10 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const std::string& aTool,
{
m_menu.ShowContextMenu( selection() );
}
else if( evt->IsAction( &PCB_ACTIONS::trackViaSizeChanged ) )
{
m_toolMgr->RunAction( ACTIONS::refreshPreview );
}
else if( newItem && evt->Category() == TC_COMMAND )
{
/*
@ -211,7 +215,8 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const std::string& aTool,
preview.Clear();
newItem.release();
makeNewItem( controls()->GetCursorPosition() );
makeNewItem( (wxPoint) cursorPos );
aPlacer->SnapItem( newItem.get() );
view()->Update( &preview );
}
}
@ -219,7 +224,7 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const std::string& aTool,
else if( newItem && evt->IsMotion() )
{
// track the cursor
newItem->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
newItem->SetPosition( (wxPoint) cursorPos );
aPlacer->SnapItem( newItem.get() );
// Show a preview of the item