Loading common/tool/context_menu.cpp +65 −56 Original line number Original line Diff line number Diff line Loading @@ -26,14 +26,14 @@ #include <tool/tool_manager.h> #include <tool/tool_manager.h> #include <tool/tool_interactive.h> #include <tool/tool_interactive.h> #include <tool/context_menu.h> #include <tool/context_menu.h> #include <boost/bind.hpp> #include <boost/bind.hpp> #include <cassert> #include <cassert> CONTEXT_MENU::CONTEXT_MENU() : CONTEXT_MENU::CONTEXT_MENU() : m_titleSet( false ), m_selected( -1 ), m_tool( NULL ) m_titleSet( false ), m_selected( -1 ), m_tool( NULL ), m_icon( NULL ) { { setCustomEventHandler( boost::bind( &CONTEXT_MENU::handleCustomEvent, this, _1 ) ); setCustomEventHandler( boost::bind( &CONTEXT_MENU::handleCustomEvent, this, _1 ) ); setupEvents(); setupEvents(); } } Loading @@ -42,31 +42,7 @@ CONTEXT_MENU::CONTEXT_MENU( const CONTEXT_MENU& aMenu ) : m_titleSet( aMenu.m_titleSet ), m_selected( -1 ), m_tool( aMenu.m_tool ), m_titleSet( aMenu.m_titleSet ), m_selected( -1 ), m_tool( aMenu.m_tool ), m_toolActions( aMenu.m_toolActions ), m_customHandler( aMenu.m_customHandler ) m_toolActions( aMenu.m_toolActions ), m_customHandler( aMenu.m_customHandler ) { { // Copy all the menu entries copyFrom( aMenu ); for( unsigned i = 0; i < aMenu.GetMenuItemCount(); ++i ) { wxMenuItem* item = aMenu.FindItemByPosition( i ); if( item->IsSubMenu() ) { #ifdef DEBUG // Submenus of a CONTEXT_MENU are supposed to be CONTEXT_MENUs as well assert( dynamic_cast<CONTEXT_MENU*>( item->GetSubMenu() ) ); #endif CONTEXT_MENU* menu = new CONTEXT_MENU( static_cast<const CONTEXT_MENU&>( *item->GetSubMenu() ) ); AppendSubMenu( menu, item->GetItemLabel(), wxEmptyString ); } else { wxMenuItem* newItem = new wxMenuItem( this, item->GetId(), item->GetItemLabel(), wxEmptyString, item->GetKind() ); Append( newItem ); copyItem( item, newItem ); } } setupEvents(); setupEvents(); } } Loading @@ -81,31 +57,7 @@ CONTEXT_MENU& CONTEXT_MENU::operator=( const CONTEXT_MENU& aMenu ) m_toolActions = aMenu.m_toolActions; m_toolActions = aMenu.m_toolActions; m_customHandler = aMenu.m_customHandler; m_customHandler = aMenu.m_customHandler; // Copy all the menu entries copyFrom( aMenu ); for( unsigned i = 0; i < aMenu.GetMenuItemCount(); ++i ) { wxMenuItem* item = aMenu.FindItemByPosition( i ); if( item->IsSubMenu() ) { #ifdef DEBUG // Submenus of a CONTEXT_MENU are supposed to be CONTEXT_MENUs as well assert( dynamic_cast<CONTEXT_MENU*>( item->GetSubMenu() ) ); #endif CONTEXT_MENU* menu = new CONTEXT_MENU( static_cast<const CONTEXT_MENU&>( *item->GetSubMenu() ) ); AppendSubMenu( menu, item->GetItemLabel(), wxEmptyString ); } else { wxMenuItem* newItem = new wxMenuItem( this, item->GetId(), item->GetItemLabel(), wxEmptyString, item->GetKind() ); Append( newItem ); copyItem( item, newItem ); } } setupEvents(); setupEvents(); return *this; return *this; Loading Loading @@ -138,7 +90,7 @@ void CONTEXT_MENU::SetTitle( const wxString& aTitle ) } } void CONTEXT_MENU::Add( const wxString& aLabel, int aId ) void CONTEXT_MENU::Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon ) { { #ifdef DEBUG #ifdef DEBUG Loading @@ -146,7 +98,12 @@ void CONTEXT_MENU::Add( const wxString& aLabel, int aId ) wxLogWarning( wxT( "Adding more than one menu entry with the same ID may result in" wxLogWarning( wxT( "Adding more than one menu entry with the same ID may result in" "undefined behaviour" ) ); "undefined behaviour" ) ); #endif #endif Append( new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL ) ); wxMenuItem* item = new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL ); if( aIcon ) item->SetBitmap( KiBitmap( aIcon ) ); Append( item ); } } Loading @@ -154,10 +111,14 @@ void CONTEXT_MENU::Add( const TOOL_ACTION& aAction ) { { /// ID numbers for tool actions need to have a value higher than m_actionId /// ID numbers for tool actions need to have a value higher than m_actionId int id = m_actionId + aAction.GetId(); int id = m_actionId + aAction.GetId(); const BITMAP_OPAQUE* icon = aAction.GetIcon(); wxMenuItem* item = new wxMenuItem( this, id, wxMenuItem* item = new wxMenuItem( this, id, aAction.GetMenuItem(), aAction.GetDescription(), wxITEM_NORMAL ); aAction.GetMenuItem(), aAction.GetDescription(), wxITEM_NORMAL ); if( icon ) item->SetBitmap( KiBitmap( icon ) ); if( aAction.HasHotKey() ) if( aAction.HasHotKey() ) { { int key = aAction.GetHotKey() & ~MD_MODIFIER_MASK; int key = aAction.GetHotKey() & ~MD_MODIFIER_MASK; Loading @@ -180,6 +141,22 @@ void CONTEXT_MENU::Add( const TOOL_ACTION& aAction ) } } void CONTEXT_MENU::Add( CONTEXT_MENU* aMenu, const wxString& aLabel ) { if( aMenu->m_icon ) { wxMenuItem* newItem = new wxMenuItem( this, -1, aLabel, wxEmptyString, wxITEM_NORMAL ); newItem->SetBitmap( KiBitmap( aMenu->m_icon ) ); newItem->SetSubMenu( aMenu ); Append( newItem ); } else { AppendSubMenu( aMenu, aLabel ); } } void CONTEXT_MENU::Clear() void CONTEXT_MENU::Clear() { { m_titleSet = false; m_titleSet = false; Loading Loading @@ -277,7 +254,39 @@ void CONTEXT_MENU::copyItem( const wxMenuItem* aSource, wxMenuItem* aDest ) cons if( aSource->IsCheckable() ) if( aSource->IsCheckable() ) aDest->Check( aSource->IsChecked() ); aDest->Check( aSource->IsChecked() ); } if( aSource->GetKind() == wxITEM_NORMAL ) aDest->SetBitmap( aSource->GetBitmap() ); void CONTEXT_MENU::copyFrom( const CONTEXT_MENU& aMenu ) { m_icon = aMenu.m_icon; // Copy all the menu entries for( unsigned i = 0; i < aMenu.GetMenuItemCount(); ++i ) { wxMenuItem* item = aMenu.FindItemByPosition( i ); wxMenuItem* newItem = new wxMenuItem( this, item->GetId(), item->GetItemLabel(), item->GetHelp(), item->GetKind() ); if( item->GetKind() == wxITEM_NORMAL ) newItem->SetBitmap( item->GetBitmap() ); if( item->IsSubMenu() ) { #ifdef DEBUG // Submenus of a CONTEXT_MENU are supposed to be CONTEXT_MENUs as well assert( dynamic_cast<CONTEXT_MENU*>( item->GetSubMenu() ) ); #endif CONTEXT_MENU* menu = new CONTEXT_MENU( static_cast<const CONTEXT_MENU&>( *item->GetSubMenu() ) ); newItem->SetSubMenu( menu ); Append( newItem ); } else { Append( newItem ); copyItem( item, newItem ); } } } } include/tool/context_menu.h +27 −1 Original line number Original line Diff line number Diff line Loading @@ -59,14 +59,25 @@ public: */ */ void SetTitle( const wxString& aTitle ); void SetTitle( const wxString& aTitle ); /** * Function SetIcon() * Assigns an icon for the entry. * @param aIcon is the icon to be assigned. NULL is used to remove icon. */ void SetIcon( const BITMAP_OPAQUE* aIcon ) { m_icon = aIcon; } /** /** * Function Add() * Function Add() * Adds an entry to the menu. After highlighting/selecting the entry, a TOOL_EVENT command is * Adds an entry to the menu. After highlighting/selecting the entry, a TOOL_EVENT command is * sent that contains ID of the entry. * sent that contains ID of the entry. * @param aLabel is the text label show in the menu. * @param aLabel is the text label show in the menu. * @param aId is the ID that is sent in the TOOL_EVENT. It should be unique for every entry. * @param aId is the ID that is sent in the TOOL_EVENT. It should be unique for every entry. * @param aIcon is an optional icon. */ */ void Add( const wxString& aLabel, int aId ); void Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon = NULL ); /** /** * Function Add() * Function Add() Loading @@ -76,6 +87,15 @@ public: */ */ void Add( const TOOL_ACTION& aAction ); void Add( const TOOL_ACTION& aAction ); /** * Function Add() * Adds a context menu as a submenu. The difference between this function and wxMenu::AppendSubMenu() * is the capability to handle icons. * @param aMenu is the submenu to be added. * @param aLabel is the caption displayed for the menu entry. */ void Add( CONTEXT_MENU* aMenu, const wxString& aLabel ); /** /** * Function Clear() * Function Clear() * Removes all the entries from the menu (as well as its title). It leaves the menu in the * Removes all the entries from the menu (as well as its title). It leaves the menu in the Loading Loading @@ -112,6 +132,9 @@ private: */ */ void copyItem( const wxMenuItem* aSource, wxMenuItem* aDest ) const; void copyItem( const wxMenuItem* aSource, wxMenuItem* aDest ) const; ///> Common part of copy constructor and assignment operator. void copyFrom( const CONTEXT_MENU& aMenu ); ///> Initializes handlers for events. ///> Initializes handlers for events. void setupEvents(); void setupEvents(); Loading Loading @@ -146,6 +169,9 @@ private: /// Custom events handler, allows to translate wxEvents to TOOL_EVENTs. /// Custom events handler, allows to translate wxEvents to TOOL_EVENTs. boost::function<OPT_TOOL_EVENT(const wxMenuEvent& aEvent)> m_customHandler; boost::function<OPT_TOOL_EVENT(const wxMenuEvent& aEvent)> m_customHandler; /// Optional icon const BITMAP_OPAQUE* m_icon; friend class TOOL_INTERACTIVE; friend class TOOL_INTERACTIVE; }; }; Loading include/tool/tool_action.h +14 −3 Original line number Original line Diff line number Diff line Loading @@ -31,6 +31,8 @@ #include <tool/tool_manager.h> #include <tool/tool_manager.h> struct BITMAP_OPAQUE; /** /** * Class TOOL_ACTION * Class TOOL_ACTION * * Loading @@ -46,10 +48,11 @@ class TOOL_ACTION public: public: TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT, TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT, int aDefaultHotKey = 0, const wxString aMenuItem = wxEmptyString, int aDefaultHotKey = 0, const wxString aMenuItem = wxEmptyString, const wxString& aMenuDesc = wxEmptyString, TOOL_ACTION_FLAGS aFlags = AF_NONE ) : const wxString& aMenuDesc = wxEmptyString, const BITMAP_OPAQUE* aIcon = NULL, TOOL_ACTION_FLAGS aFlags = AF_NONE ) : m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ), m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ), m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ), m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ), m_menuDescription( aMenuDesc ), m_id( -1 ), m_flags( aFlags ) m_menuDescription( aMenuDesc ), m_icon( aIcon ), m_id( -1 ), m_flags( aFlags ) { { TOOL_MANAGER::GetActionList().push_back( this ); TOOL_MANAGER::GetActionList().push_back( this ); } } Loading Loading @@ -202,6 +205,14 @@ public: return m_flags & AF_NOTIFY; return m_flags & AF_NOTIFY; } } /** * Returns an icon associated with the action. It is used in context menu. */ const BITMAP_OPAQUE* GetIcon() const { return m_icon; } private: private: friend class ACTION_MANAGER; friend class ACTION_MANAGER; Loading @@ -224,7 +235,7 @@ private: wxString m_menuDescription; wxString m_menuDescription; // Icon for menu entry // Icon for menu entry // KiBitmap m_bitmap; const BITMAP_OPAQUE* m_icon; /// Unique ID for fast matching. Assigned by ACTION_MANAGER. /// Unique ID for fast matching. Assigned by ACTION_MANAGER. int m_id; int m_id; Loading pcbnew/router/router_menus.h +17 −8 Original line number Original line Diff line number Diff line Loading @@ -57,7 +57,7 @@ using boost::optional; static TOOL_ACTION ACT_NewTrack( "pcbnew.InteractiveRouter.NewTrack", static TOOL_ACTION ACT_NewTrack( "pcbnew.InteractiveRouter.NewTrack", AS_CONTEXT, 'X', AS_CONTEXT, 'X', _( "New Track" ), _( "Starts laying a new track." ) ); _( "New Track" ), _( "Starts laying a new track." ), add_tracks_xpm ); static TOOL_ACTION ACT_EndTrack( "pcbnew.InteractiveRouter.EndTrack", static TOOL_ACTION ACT_EndTrack( "pcbnew.InteractiveRouter.EndTrack", AS_CONTEXT, WXK_END, AS_CONTEXT, WXK_END, Loading @@ -69,7 +69,7 @@ static TOOL_ACTION ACT_AutoEndRoute( "pcbnew.InteractiveRouter.AutoEndRoute", static TOOL_ACTION ACT_Drag( "pcbnew.InteractiveRouter.Drag", static TOOL_ACTION ACT_Drag( "pcbnew.InteractiveRouter.Drag", AS_CONTEXT, 'G', AS_CONTEXT, 'G', _( "Drag Track/Via" ), _( "Drags a track or a via." ) ); _( "Drag Track/Via" ), _( "Drags a track or a via." ), drag_track_segment_xpm ); static TOOL_ACTION ACT_PlaceThroughVia( "pcbnew.InteractiveRouter.PlaceVia", static TOOL_ACTION ACT_PlaceThroughVia( "pcbnew.InteractiveRouter.PlaceVia", AS_CONTEXT, 'V', AS_CONTEXT, 'V', Loading @@ -93,7 +93,8 @@ static TOOL_ACTION ACT_RouterOptions( "pcbnew.InteractiveRouter.RouterOptions", static TOOL_ACTION ACT_SwitchPosture( "pcbnew.InteractiveRouter.SwitchPosture", static TOOL_ACTION ACT_SwitchPosture( "pcbnew.InteractiveRouter.SwitchPosture", AS_CONTEXT, '/', AS_CONTEXT, '/', _( "Switch Track Posture" ), _( "Switches posture of the currenly routed track." ) ); _( "Switch Track Posture" ), _( "Switches posture of the currenly routed track." ), change_entry_orient_xpm ); static TOOL_ACTION ACT_SetDpDimensions( "pcbnew.InteractiveRouter.SetDpDimensions", static TOOL_ACTION ACT_SetDpDimensions( "pcbnew.InteractiveRouter.SetDpDimensions", AS_CONTEXT, 'D', AS_CONTEXT, 'D', Loading Loading @@ -143,14 +144,22 @@ public: wxString msg; wxString msg; m_board = aBoard; m_board = aBoard; Append( ID_POPUP_PCB_SELECT_CUSTOM_WIDTH, _( "Custom size" ), wxMenuItem* custom_width = new wxMenu( ID_POPUP_PCB_SELECT_CUSTOM_WIDTH, _( "Custom size" ), wxEmptyString, wxITEM_CHECK ); _( "Allows to specify any track/via size" ), wxITEM_CHECK ); //custom->SetBitmap(); // TODO missing icon Append( custom_width ); Append( ID_POPUP_PCB_SELECT_AUTO_WIDTH, _( "Use the starting track width" ), wxMenuItem* auto_width = new wxMenu( ID_POPUP_PCB_SELECT_AUTO_WIDTH, _( "Route using the width of the starting track." ), wxITEM_CHECK ); _( "Use the starting track width" ), _( "Route using the width of the starting track" ), wxITEM_CHECK ); auto_width->SetBitmap( KiBitmap( auto_track_width_xpm ) ); Append( auto_width ); Append( ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES, _( "Use netclass values" ), wxMenuItem* net_width = new wxMenu( ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES, _( "Use netclass values" ), _( "Use track and via sizes from the net class" ), wxITEM_CHECK ); _( "Use track and via sizes from the net class" ), wxITEM_CHECK ); //net_width->SetBitmap(); // TODO missing icon Append( net_width ); for( unsigned i = 0; i < bds.m_TrackWidthList.size(); i++ ) for( unsigned i = 0; i < bds.m_TrackWidthList.size(); i++ ) { { Loading pcbnew/router/router_tool.cpp +7 −6 Original line number Original line Diff line number Diff line Loading @@ -53,19 +53,19 @@ using namespace KIGFX; using boost::optional; using boost::optional; static TOOL_ACTION ACT_NewTrack( "pcbnew.InteractiveRouter.NewTrack", AS_CONTEXT, 'X', static TOOL_ACTION ACT_NewTrack( "pcbnew.InteractiveRouter.NewTrack", AS_CONTEXT, 'X', _( "New Track" ), _( "Starts laying a new track." ) ); _( "New Track" ), _( "Starts laying a new track." ), add_tracks_xpm ); static TOOL_ACTION ACT_EndTrack( "pcbnew.InteractiveRouter.EndTrack", AS_CONTEXT, WXK_END, static TOOL_ACTION ACT_EndTrack( "pcbnew.InteractiveRouter.EndTrack", AS_CONTEXT, WXK_END, _( "End Track" ), _( "Stops laying the current track." ) ); _( "End Track" ), _( "Stops laying the current track." ), checked_ok_xpm ); static TOOL_ACTION ACT_AutoEndRoute( "pcbnew.InteractiveRouter.AutoEndRoute", AS_CONTEXT, 'F', static TOOL_ACTION ACT_AutoEndRoute( "pcbnew.InteractiveRouter.AutoEndRoute", AS_CONTEXT, 'F', _( "Auto-end Track" ), _( "Automagically finishes currently routed track." ) ); _( "Auto-end Track" ), _( "Automagically finishes currently routed track." ) ); static TOOL_ACTION ACT_Drag( "pcbnew.InteractiveRouter.Drag", AS_CONTEXT, 'G', static TOOL_ACTION ACT_Drag( "pcbnew.InteractiveRouter.Drag", AS_CONTEXT, 'G', _( "Drag Track/Via" ), _( "Drags a track or a via." ) ); _( "Drag Track/Via" ), _( "Drags a track or a via." ), drag_track_segment_xpm ); static TOOL_ACTION ACT_PlaceThroughVia( "pcbnew.InteractiveRouter.PlaceVia", AS_CONTEXT, 'V', static TOOL_ACTION ACT_PlaceThroughVia( "pcbnew.InteractiveRouter.PlaceVia", AS_CONTEXT, 'V', _( "Place Through Via" ), _( "Adds a through-hole via at the end of currently routed track." ) ); _( "Place Through Via" ), _( "Adds a through-hole via at the end of currently routed track." ), via_xpm ); static TOOL_ACTION ACT_PlaceBlindVia( "pcbnew.InteractiveRouter.PlaceBlindVia", AS_CONTEXT, 'Z', static TOOL_ACTION ACT_PlaceBlindVia( "pcbnew.InteractiveRouter.PlaceBlindVia", AS_CONTEXT, 'Z', _( "Place Blind/Buried Via" ), _( "Adds a blind or buried via at the end of currently routed track." ) ); _( "Place Blind/Buried Via" ), _( "Adds a blind or buried via at the end of currently routed track." ) ); Loading @@ -77,7 +77,7 @@ static TOOL_ACTION ACT_CustomTrackWidth( "pcbnew.InteractiveRouter.CustomTrackWi _( "Custom Track Width" ), _( "Shows a dialog for changing the track width and via size." ) ); _( "Custom Track Width" ), _( "Shows a dialog for changing the track width and via size." ) ); static TOOL_ACTION ACT_SwitchPosture( "pcbnew.InteractiveRouter.SwitchPosture", AS_CONTEXT, '/', static TOOL_ACTION ACT_SwitchPosture( "pcbnew.InteractiveRouter.SwitchPosture", AS_CONTEXT, '/', _( "Switch Track Posture" ), _( "Switches posture of the currenly routed track." ) ); _( "Switch Track Posture" ), _( "Switches posture of the currenly routed track." ), change_entry_orient_xpm ); static TOOL_ACTION ACT_SetDpDimensions( "pcbnew.InteractiveRouter.SetDpDimensions", AS_CONTEXT, 'D', static TOOL_ACTION ACT_SetDpDimensions( "pcbnew.InteractiveRouter.SetDpDimensions", AS_CONTEXT, 'D', _( "Differential Pair Dimensions..." ), _( "Sets the width and gap of the currently routed differential pair." ) ); _( "Differential Pair Dimensions..." ), _( "Sets the width and gap of the currently routed differential pair." ) ); Loading @@ -94,6 +94,7 @@ class CONTEXT_TRACK_WIDTH_MENU: public CONTEXT_MENU public: public: CONTEXT_TRACK_WIDTH_MENU() CONTEXT_TRACK_WIDTH_MENU() { { SetIcon( width_track_via_xpm ); setCustomEventHandler( boost::bind( &CONTEXT_TRACK_WIDTH_MENU::handleCustomEvent, setCustomEventHandler( boost::bind( &CONTEXT_TRACK_WIDTH_MENU::handleCustomEvent, this, _1 ) ); this, _1 ) ); } } Loading Loading @@ -224,7 +225,7 @@ public: CONTEXT_TRACK_WIDTH_MENU* trackMenu = new CONTEXT_TRACK_WIDTH_MENU; CONTEXT_TRACK_WIDTH_MENU* trackMenu = new CONTEXT_TRACK_WIDTH_MENU; trackMenu->SetBoard( aBoard ); trackMenu->SetBoard( aBoard ); AppendSubMenu( trackMenu, _( "Select Track Width" ) ); Add( trackMenu, _( "Select Track/Via Width" ) ); Add( ACT_CustomTrackWidth ); Add( ACT_CustomTrackWidth ); Loading Loading
common/tool/context_menu.cpp +65 −56 Original line number Original line Diff line number Diff line Loading @@ -26,14 +26,14 @@ #include <tool/tool_manager.h> #include <tool/tool_manager.h> #include <tool/tool_interactive.h> #include <tool/tool_interactive.h> #include <tool/context_menu.h> #include <tool/context_menu.h> #include <boost/bind.hpp> #include <boost/bind.hpp> #include <cassert> #include <cassert> CONTEXT_MENU::CONTEXT_MENU() : CONTEXT_MENU::CONTEXT_MENU() : m_titleSet( false ), m_selected( -1 ), m_tool( NULL ) m_titleSet( false ), m_selected( -1 ), m_tool( NULL ), m_icon( NULL ) { { setCustomEventHandler( boost::bind( &CONTEXT_MENU::handleCustomEvent, this, _1 ) ); setCustomEventHandler( boost::bind( &CONTEXT_MENU::handleCustomEvent, this, _1 ) ); setupEvents(); setupEvents(); } } Loading @@ -42,31 +42,7 @@ CONTEXT_MENU::CONTEXT_MENU( const CONTEXT_MENU& aMenu ) : m_titleSet( aMenu.m_titleSet ), m_selected( -1 ), m_tool( aMenu.m_tool ), m_titleSet( aMenu.m_titleSet ), m_selected( -1 ), m_tool( aMenu.m_tool ), m_toolActions( aMenu.m_toolActions ), m_customHandler( aMenu.m_customHandler ) m_toolActions( aMenu.m_toolActions ), m_customHandler( aMenu.m_customHandler ) { { // Copy all the menu entries copyFrom( aMenu ); for( unsigned i = 0; i < aMenu.GetMenuItemCount(); ++i ) { wxMenuItem* item = aMenu.FindItemByPosition( i ); if( item->IsSubMenu() ) { #ifdef DEBUG // Submenus of a CONTEXT_MENU are supposed to be CONTEXT_MENUs as well assert( dynamic_cast<CONTEXT_MENU*>( item->GetSubMenu() ) ); #endif CONTEXT_MENU* menu = new CONTEXT_MENU( static_cast<const CONTEXT_MENU&>( *item->GetSubMenu() ) ); AppendSubMenu( menu, item->GetItemLabel(), wxEmptyString ); } else { wxMenuItem* newItem = new wxMenuItem( this, item->GetId(), item->GetItemLabel(), wxEmptyString, item->GetKind() ); Append( newItem ); copyItem( item, newItem ); } } setupEvents(); setupEvents(); } } Loading @@ -81,31 +57,7 @@ CONTEXT_MENU& CONTEXT_MENU::operator=( const CONTEXT_MENU& aMenu ) m_toolActions = aMenu.m_toolActions; m_toolActions = aMenu.m_toolActions; m_customHandler = aMenu.m_customHandler; m_customHandler = aMenu.m_customHandler; // Copy all the menu entries copyFrom( aMenu ); for( unsigned i = 0; i < aMenu.GetMenuItemCount(); ++i ) { wxMenuItem* item = aMenu.FindItemByPosition( i ); if( item->IsSubMenu() ) { #ifdef DEBUG // Submenus of a CONTEXT_MENU are supposed to be CONTEXT_MENUs as well assert( dynamic_cast<CONTEXT_MENU*>( item->GetSubMenu() ) ); #endif CONTEXT_MENU* menu = new CONTEXT_MENU( static_cast<const CONTEXT_MENU&>( *item->GetSubMenu() ) ); AppendSubMenu( menu, item->GetItemLabel(), wxEmptyString ); } else { wxMenuItem* newItem = new wxMenuItem( this, item->GetId(), item->GetItemLabel(), wxEmptyString, item->GetKind() ); Append( newItem ); copyItem( item, newItem ); } } setupEvents(); setupEvents(); return *this; return *this; Loading Loading @@ -138,7 +90,7 @@ void CONTEXT_MENU::SetTitle( const wxString& aTitle ) } } void CONTEXT_MENU::Add( const wxString& aLabel, int aId ) void CONTEXT_MENU::Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon ) { { #ifdef DEBUG #ifdef DEBUG Loading @@ -146,7 +98,12 @@ void CONTEXT_MENU::Add( const wxString& aLabel, int aId ) wxLogWarning( wxT( "Adding more than one menu entry with the same ID may result in" wxLogWarning( wxT( "Adding more than one menu entry with the same ID may result in" "undefined behaviour" ) ); "undefined behaviour" ) ); #endif #endif Append( new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL ) ); wxMenuItem* item = new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL ); if( aIcon ) item->SetBitmap( KiBitmap( aIcon ) ); Append( item ); } } Loading @@ -154,10 +111,14 @@ void CONTEXT_MENU::Add( const TOOL_ACTION& aAction ) { { /// ID numbers for tool actions need to have a value higher than m_actionId /// ID numbers for tool actions need to have a value higher than m_actionId int id = m_actionId + aAction.GetId(); int id = m_actionId + aAction.GetId(); const BITMAP_OPAQUE* icon = aAction.GetIcon(); wxMenuItem* item = new wxMenuItem( this, id, wxMenuItem* item = new wxMenuItem( this, id, aAction.GetMenuItem(), aAction.GetDescription(), wxITEM_NORMAL ); aAction.GetMenuItem(), aAction.GetDescription(), wxITEM_NORMAL ); if( icon ) item->SetBitmap( KiBitmap( icon ) ); if( aAction.HasHotKey() ) if( aAction.HasHotKey() ) { { int key = aAction.GetHotKey() & ~MD_MODIFIER_MASK; int key = aAction.GetHotKey() & ~MD_MODIFIER_MASK; Loading @@ -180,6 +141,22 @@ void CONTEXT_MENU::Add( const TOOL_ACTION& aAction ) } } void CONTEXT_MENU::Add( CONTEXT_MENU* aMenu, const wxString& aLabel ) { if( aMenu->m_icon ) { wxMenuItem* newItem = new wxMenuItem( this, -1, aLabel, wxEmptyString, wxITEM_NORMAL ); newItem->SetBitmap( KiBitmap( aMenu->m_icon ) ); newItem->SetSubMenu( aMenu ); Append( newItem ); } else { AppendSubMenu( aMenu, aLabel ); } } void CONTEXT_MENU::Clear() void CONTEXT_MENU::Clear() { { m_titleSet = false; m_titleSet = false; Loading Loading @@ -277,7 +254,39 @@ void CONTEXT_MENU::copyItem( const wxMenuItem* aSource, wxMenuItem* aDest ) cons if( aSource->IsCheckable() ) if( aSource->IsCheckable() ) aDest->Check( aSource->IsChecked() ); aDest->Check( aSource->IsChecked() ); } if( aSource->GetKind() == wxITEM_NORMAL ) aDest->SetBitmap( aSource->GetBitmap() ); void CONTEXT_MENU::copyFrom( const CONTEXT_MENU& aMenu ) { m_icon = aMenu.m_icon; // Copy all the menu entries for( unsigned i = 0; i < aMenu.GetMenuItemCount(); ++i ) { wxMenuItem* item = aMenu.FindItemByPosition( i ); wxMenuItem* newItem = new wxMenuItem( this, item->GetId(), item->GetItemLabel(), item->GetHelp(), item->GetKind() ); if( item->GetKind() == wxITEM_NORMAL ) newItem->SetBitmap( item->GetBitmap() ); if( item->IsSubMenu() ) { #ifdef DEBUG // Submenus of a CONTEXT_MENU are supposed to be CONTEXT_MENUs as well assert( dynamic_cast<CONTEXT_MENU*>( item->GetSubMenu() ) ); #endif CONTEXT_MENU* menu = new CONTEXT_MENU( static_cast<const CONTEXT_MENU&>( *item->GetSubMenu() ) ); newItem->SetSubMenu( menu ); Append( newItem ); } else { Append( newItem ); copyItem( item, newItem ); } } } }
include/tool/context_menu.h +27 −1 Original line number Original line Diff line number Diff line Loading @@ -59,14 +59,25 @@ public: */ */ void SetTitle( const wxString& aTitle ); void SetTitle( const wxString& aTitle ); /** * Function SetIcon() * Assigns an icon for the entry. * @param aIcon is the icon to be assigned. NULL is used to remove icon. */ void SetIcon( const BITMAP_OPAQUE* aIcon ) { m_icon = aIcon; } /** /** * Function Add() * Function Add() * Adds an entry to the menu. After highlighting/selecting the entry, a TOOL_EVENT command is * Adds an entry to the menu. After highlighting/selecting the entry, a TOOL_EVENT command is * sent that contains ID of the entry. * sent that contains ID of the entry. * @param aLabel is the text label show in the menu. * @param aLabel is the text label show in the menu. * @param aId is the ID that is sent in the TOOL_EVENT. It should be unique for every entry. * @param aId is the ID that is sent in the TOOL_EVENT. It should be unique for every entry. * @param aIcon is an optional icon. */ */ void Add( const wxString& aLabel, int aId ); void Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon = NULL ); /** /** * Function Add() * Function Add() Loading @@ -76,6 +87,15 @@ public: */ */ void Add( const TOOL_ACTION& aAction ); void Add( const TOOL_ACTION& aAction ); /** * Function Add() * Adds a context menu as a submenu. The difference between this function and wxMenu::AppendSubMenu() * is the capability to handle icons. * @param aMenu is the submenu to be added. * @param aLabel is the caption displayed for the menu entry. */ void Add( CONTEXT_MENU* aMenu, const wxString& aLabel ); /** /** * Function Clear() * Function Clear() * Removes all the entries from the menu (as well as its title). It leaves the menu in the * Removes all the entries from the menu (as well as its title). It leaves the menu in the Loading Loading @@ -112,6 +132,9 @@ private: */ */ void copyItem( const wxMenuItem* aSource, wxMenuItem* aDest ) const; void copyItem( const wxMenuItem* aSource, wxMenuItem* aDest ) const; ///> Common part of copy constructor and assignment operator. void copyFrom( const CONTEXT_MENU& aMenu ); ///> Initializes handlers for events. ///> Initializes handlers for events. void setupEvents(); void setupEvents(); Loading Loading @@ -146,6 +169,9 @@ private: /// Custom events handler, allows to translate wxEvents to TOOL_EVENTs. /// Custom events handler, allows to translate wxEvents to TOOL_EVENTs. boost::function<OPT_TOOL_EVENT(const wxMenuEvent& aEvent)> m_customHandler; boost::function<OPT_TOOL_EVENT(const wxMenuEvent& aEvent)> m_customHandler; /// Optional icon const BITMAP_OPAQUE* m_icon; friend class TOOL_INTERACTIVE; friend class TOOL_INTERACTIVE; }; }; Loading
include/tool/tool_action.h +14 −3 Original line number Original line Diff line number Diff line Loading @@ -31,6 +31,8 @@ #include <tool/tool_manager.h> #include <tool/tool_manager.h> struct BITMAP_OPAQUE; /** /** * Class TOOL_ACTION * Class TOOL_ACTION * * Loading @@ -46,10 +48,11 @@ class TOOL_ACTION public: public: TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT, TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT, int aDefaultHotKey = 0, const wxString aMenuItem = wxEmptyString, int aDefaultHotKey = 0, const wxString aMenuItem = wxEmptyString, const wxString& aMenuDesc = wxEmptyString, TOOL_ACTION_FLAGS aFlags = AF_NONE ) : const wxString& aMenuDesc = wxEmptyString, const BITMAP_OPAQUE* aIcon = NULL, TOOL_ACTION_FLAGS aFlags = AF_NONE ) : m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ), m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ), m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ), m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ), m_menuDescription( aMenuDesc ), m_id( -1 ), m_flags( aFlags ) m_menuDescription( aMenuDesc ), m_icon( aIcon ), m_id( -1 ), m_flags( aFlags ) { { TOOL_MANAGER::GetActionList().push_back( this ); TOOL_MANAGER::GetActionList().push_back( this ); } } Loading Loading @@ -202,6 +205,14 @@ public: return m_flags & AF_NOTIFY; return m_flags & AF_NOTIFY; } } /** * Returns an icon associated with the action. It is used in context menu. */ const BITMAP_OPAQUE* GetIcon() const { return m_icon; } private: private: friend class ACTION_MANAGER; friend class ACTION_MANAGER; Loading @@ -224,7 +235,7 @@ private: wxString m_menuDescription; wxString m_menuDescription; // Icon for menu entry // Icon for menu entry // KiBitmap m_bitmap; const BITMAP_OPAQUE* m_icon; /// Unique ID for fast matching. Assigned by ACTION_MANAGER. /// Unique ID for fast matching. Assigned by ACTION_MANAGER. int m_id; int m_id; Loading
pcbnew/router/router_menus.h +17 −8 Original line number Original line Diff line number Diff line Loading @@ -57,7 +57,7 @@ using boost::optional; static TOOL_ACTION ACT_NewTrack( "pcbnew.InteractiveRouter.NewTrack", static TOOL_ACTION ACT_NewTrack( "pcbnew.InteractiveRouter.NewTrack", AS_CONTEXT, 'X', AS_CONTEXT, 'X', _( "New Track" ), _( "Starts laying a new track." ) ); _( "New Track" ), _( "Starts laying a new track." ), add_tracks_xpm ); static TOOL_ACTION ACT_EndTrack( "pcbnew.InteractiveRouter.EndTrack", static TOOL_ACTION ACT_EndTrack( "pcbnew.InteractiveRouter.EndTrack", AS_CONTEXT, WXK_END, AS_CONTEXT, WXK_END, Loading @@ -69,7 +69,7 @@ static TOOL_ACTION ACT_AutoEndRoute( "pcbnew.InteractiveRouter.AutoEndRoute", static TOOL_ACTION ACT_Drag( "pcbnew.InteractiveRouter.Drag", static TOOL_ACTION ACT_Drag( "pcbnew.InteractiveRouter.Drag", AS_CONTEXT, 'G', AS_CONTEXT, 'G', _( "Drag Track/Via" ), _( "Drags a track or a via." ) ); _( "Drag Track/Via" ), _( "Drags a track or a via." ), drag_track_segment_xpm ); static TOOL_ACTION ACT_PlaceThroughVia( "pcbnew.InteractiveRouter.PlaceVia", static TOOL_ACTION ACT_PlaceThroughVia( "pcbnew.InteractiveRouter.PlaceVia", AS_CONTEXT, 'V', AS_CONTEXT, 'V', Loading @@ -93,7 +93,8 @@ static TOOL_ACTION ACT_RouterOptions( "pcbnew.InteractiveRouter.RouterOptions", static TOOL_ACTION ACT_SwitchPosture( "pcbnew.InteractiveRouter.SwitchPosture", static TOOL_ACTION ACT_SwitchPosture( "pcbnew.InteractiveRouter.SwitchPosture", AS_CONTEXT, '/', AS_CONTEXT, '/', _( "Switch Track Posture" ), _( "Switches posture of the currenly routed track." ) ); _( "Switch Track Posture" ), _( "Switches posture of the currenly routed track." ), change_entry_orient_xpm ); static TOOL_ACTION ACT_SetDpDimensions( "pcbnew.InteractiveRouter.SetDpDimensions", static TOOL_ACTION ACT_SetDpDimensions( "pcbnew.InteractiveRouter.SetDpDimensions", AS_CONTEXT, 'D', AS_CONTEXT, 'D', Loading Loading @@ -143,14 +144,22 @@ public: wxString msg; wxString msg; m_board = aBoard; m_board = aBoard; Append( ID_POPUP_PCB_SELECT_CUSTOM_WIDTH, _( "Custom size" ), wxMenuItem* custom_width = new wxMenu( ID_POPUP_PCB_SELECT_CUSTOM_WIDTH, _( "Custom size" ), wxEmptyString, wxITEM_CHECK ); _( "Allows to specify any track/via size" ), wxITEM_CHECK ); //custom->SetBitmap(); // TODO missing icon Append( custom_width ); Append( ID_POPUP_PCB_SELECT_AUTO_WIDTH, _( "Use the starting track width" ), wxMenuItem* auto_width = new wxMenu( ID_POPUP_PCB_SELECT_AUTO_WIDTH, _( "Route using the width of the starting track." ), wxITEM_CHECK ); _( "Use the starting track width" ), _( "Route using the width of the starting track" ), wxITEM_CHECK ); auto_width->SetBitmap( KiBitmap( auto_track_width_xpm ) ); Append( auto_width ); Append( ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES, _( "Use netclass values" ), wxMenuItem* net_width = new wxMenu( ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES, _( "Use netclass values" ), _( "Use track and via sizes from the net class" ), wxITEM_CHECK ); _( "Use track and via sizes from the net class" ), wxITEM_CHECK ); //net_width->SetBitmap(); // TODO missing icon Append( net_width ); for( unsigned i = 0; i < bds.m_TrackWidthList.size(); i++ ) for( unsigned i = 0; i < bds.m_TrackWidthList.size(); i++ ) { { Loading
pcbnew/router/router_tool.cpp +7 −6 Original line number Original line Diff line number Diff line Loading @@ -53,19 +53,19 @@ using namespace KIGFX; using boost::optional; using boost::optional; static TOOL_ACTION ACT_NewTrack( "pcbnew.InteractiveRouter.NewTrack", AS_CONTEXT, 'X', static TOOL_ACTION ACT_NewTrack( "pcbnew.InteractiveRouter.NewTrack", AS_CONTEXT, 'X', _( "New Track" ), _( "Starts laying a new track." ) ); _( "New Track" ), _( "Starts laying a new track." ), add_tracks_xpm ); static TOOL_ACTION ACT_EndTrack( "pcbnew.InteractiveRouter.EndTrack", AS_CONTEXT, WXK_END, static TOOL_ACTION ACT_EndTrack( "pcbnew.InteractiveRouter.EndTrack", AS_CONTEXT, WXK_END, _( "End Track" ), _( "Stops laying the current track." ) ); _( "End Track" ), _( "Stops laying the current track." ), checked_ok_xpm ); static TOOL_ACTION ACT_AutoEndRoute( "pcbnew.InteractiveRouter.AutoEndRoute", AS_CONTEXT, 'F', static TOOL_ACTION ACT_AutoEndRoute( "pcbnew.InteractiveRouter.AutoEndRoute", AS_CONTEXT, 'F', _( "Auto-end Track" ), _( "Automagically finishes currently routed track." ) ); _( "Auto-end Track" ), _( "Automagically finishes currently routed track." ) ); static TOOL_ACTION ACT_Drag( "pcbnew.InteractiveRouter.Drag", AS_CONTEXT, 'G', static TOOL_ACTION ACT_Drag( "pcbnew.InteractiveRouter.Drag", AS_CONTEXT, 'G', _( "Drag Track/Via" ), _( "Drags a track or a via." ) ); _( "Drag Track/Via" ), _( "Drags a track or a via." ), drag_track_segment_xpm ); static TOOL_ACTION ACT_PlaceThroughVia( "pcbnew.InteractiveRouter.PlaceVia", AS_CONTEXT, 'V', static TOOL_ACTION ACT_PlaceThroughVia( "pcbnew.InteractiveRouter.PlaceVia", AS_CONTEXT, 'V', _( "Place Through Via" ), _( "Adds a through-hole via at the end of currently routed track." ) ); _( "Place Through Via" ), _( "Adds a through-hole via at the end of currently routed track." ), via_xpm ); static TOOL_ACTION ACT_PlaceBlindVia( "pcbnew.InteractiveRouter.PlaceBlindVia", AS_CONTEXT, 'Z', static TOOL_ACTION ACT_PlaceBlindVia( "pcbnew.InteractiveRouter.PlaceBlindVia", AS_CONTEXT, 'Z', _( "Place Blind/Buried Via" ), _( "Adds a blind or buried via at the end of currently routed track." ) ); _( "Place Blind/Buried Via" ), _( "Adds a blind or buried via at the end of currently routed track." ) ); Loading @@ -77,7 +77,7 @@ static TOOL_ACTION ACT_CustomTrackWidth( "pcbnew.InteractiveRouter.CustomTrackWi _( "Custom Track Width" ), _( "Shows a dialog for changing the track width and via size." ) ); _( "Custom Track Width" ), _( "Shows a dialog for changing the track width and via size." ) ); static TOOL_ACTION ACT_SwitchPosture( "pcbnew.InteractiveRouter.SwitchPosture", AS_CONTEXT, '/', static TOOL_ACTION ACT_SwitchPosture( "pcbnew.InteractiveRouter.SwitchPosture", AS_CONTEXT, '/', _( "Switch Track Posture" ), _( "Switches posture of the currenly routed track." ) ); _( "Switch Track Posture" ), _( "Switches posture of the currenly routed track." ), change_entry_orient_xpm ); static TOOL_ACTION ACT_SetDpDimensions( "pcbnew.InteractiveRouter.SetDpDimensions", AS_CONTEXT, 'D', static TOOL_ACTION ACT_SetDpDimensions( "pcbnew.InteractiveRouter.SetDpDimensions", AS_CONTEXT, 'D', _( "Differential Pair Dimensions..." ), _( "Sets the width and gap of the currently routed differential pair." ) ); _( "Differential Pair Dimensions..." ), _( "Sets the width and gap of the currently routed differential pair." ) ); Loading @@ -94,6 +94,7 @@ class CONTEXT_TRACK_WIDTH_MENU: public CONTEXT_MENU public: public: CONTEXT_TRACK_WIDTH_MENU() CONTEXT_TRACK_WIDTH_MENU() { { SetIcon( width_track_via_xpm ); setCustomEventHandler( boost::bind( &CONTEXT_TRACK_WIDTH_MENU::handleCustomEvent, setCustomEventHandler( boost::bind( &CONTEXT_TRACK_WIDTH_MENU::handleCustomEvent, this, _1 ) ); this, _1 ) ); } } Loading Loading @@ -224,7 +225,7 @@ public: CONTEXT_TRACK_WIDTH_MENU* trackMenu = new CONTEXT_TRACK_WIDTH_MENU; CONTEXT_TRACK_WIDTH_MENU* trackMenu = new CONTEXT_TRACK_WIDTH_MENU; trackMenu->SetBoard( aBoard ); trackMenu->SetBoard( aBoard ); AppendSubMenu( trackMenu, _( "Select Track Width" ) ); Add( trackMenu, _( "Select Track/Via Width" ) ); Add( ACT_CustomTrackWidth ); Add( ACT_CustomTrackWidth ); Loading