diff --git a/eeschema/tools/sch_line_wire_bus_tool.cpp b/eeschema/tools/sch_line_wire_bus_tool.cpp index 1200f28e3e..e81243430a 100644 --- a/eeschema/tools/sch_line_wire_bus_tool.cpp +++ b/eeschema/tools/sch_line_wire_bus_tool.cpp @@ -24,27 +24,21 @@ #include -#include #include #include -#include #include #include #include #include #include -#include #include #include -#include #include #include -#include #include #include #include -#include #include #include #include @@ -52,28 +46,20 @@ #include #include #include -#include #include -#include -#include #include #include -#include #include #include -#include #include #include -#include #include #include #include #include #include -#include #include -#include #include #include diff --git a/pcbnew/edit_track_width.cpp b/pcbnew/edit_track_width.cpp index 886642d426..da712b171f 100644 --- a/pcbnew/edit_track_width.cpp +++ b/pcbnew/edit_track_width.cpp @@ -27,7 +27,8 @@ #include #include #include - +#include +#include 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 ); } diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index eda8782449..60f8f46b3d 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -55,10 +55,93 @@ #include #include #include +#include +#include using SCOPED_DRAW_MODE = SCOPED_SET_RESET; +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 viaSizeMenu = std::make_shared(); + 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 diff --git a/pcbnew/tools/pcb_tool_base.cpp b/pcbnew/tools/pcb_tool_base.cpp index 7ecd03451d..9eea0537c7 100644 --- a/pcbnew/tools/pcb_tool_base.cpp +++ b/pcbnew/tools/pcb_tool_base.cpp @@ -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