KiCad PCB EDA Suite
ACTION_TOOLBAR Class Reference

Class ACTION_TOOLBAR. More...

#include <action_toolbar.h>

Inheritance diagram for ACTION_TOOLBAR:

Public Member Functions

 ACTION_TOOLBAR (EDA_BASE_FRAME *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxAUI_TB_DEFAULT_STYLE)
 
virtual ~ACTION_TOOLBAR ()
 
void Add (const TOOL_ACTION &aAction, bool aIsToggleEntry=false)
 Function Add() Adds a TOOL_ACTION-based button to the toolbar. More...
 
void AddButton (const TOOL_ACTION &aAction)
 Function AddButton() Adds a large button such as used in the Kicad Manager Frame's launch bar. More...
 
void SetToolBitmap (const TOOL_ACTION &aAction, const wxBitmap &aBitmap)
 Function SetToolBitmap() Updates the bitmap of a particular tool. More...
 
void Toggle (const TOOL_ACTION &aAction, bool aState)
 Applies the default toggle action. More...
 
void Toggle (const TOOL_ACTION &aAction, bool aEnabled, bool aChecked)
 

Static Public Attributes

static const bool TOGGLE = true
 

Protected Member Functions

void onToolEvent (wxAuiToolBarEvent &aEvent)
 

The default tool event handler.

More...
 

Protected Attributes

TOOL_MANAGERm_toolManager
 
std::map< int, bool > m_toolKinds
 
std::map< int, const TOOL_ACTION * > m_toolActions
 

Static Protected Attributes

static const int ACTION_ID = 10000
 

Tool items with ID higher than that are considered TOOL_ACTIONs

More...
 

Detailed Description

Class ACTION_TOOLBAR.

Defines the structure of a toolbar with buttons that invoke ACTIONs.

Definition at line 41 of file action_toolbar.h.

Constructor & Destructor Documentation

◆ ACTION_TOOLBAR()

ACTION_TOOLBAR::ACTION_TOOLBAR ( EDA_BASE_FRAME parent,
wxWindowID  id = wxID_ANY,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = wxAUI_TB_DEFAULT_STYLE 
)

Definition at line 34 of file action_toolbar.cpp.

35  :
36  wxAuiToolBar( parent, id, pos, size, style ),
37  m_toolManager( parent->GetToolManager() )
38 {
39  Connect( wxEVT_COMMAND_TOOL_CLICKED, wxAuiToolBarEventHandler( ACTION_TOOLBAR::onToolEvent ), NULL, this );
40 }
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
void onToolEvent(wxAuiToolBarEvent &aEvent)
The default tool event handler.
TOOL_MANAGER * m_toolManager

References onToolEvent().

◆ ~ACTION_TOOLBAR()

virtual ACTION_TOOLBAR::~ACTION_TOOLBAR ( )
inlinevirtual

Definition at line 48 of file action_toolbar.h.

48 {}

Member Function Documentation

◆ Add()

void ACTION_TOOLBAR::Add ( const TOOL_ACTION aAction,
bool  aIsToggleEntry = false 
)

Function Add() Adds a TOOL_ACTION-based button to the toolbar.

After selecting the entry, a TOOL_EVENT command containing name of the action is sent.

Definition at line 43 of file action_toolbar.cpp.

44 {
46  int toolId = aAction.GetId() + ACTION_ID;
47 
48  AddTool( toolId, wxEmptyString, KiScaledBitmap( aAction.GetIcon(), editFrame ),
49  aAction.GetDescription(), aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL );
50 
51  m_toolKinds[ toolId ] = aIsToggleEntry;
52  m_toolActions[ toolId ] = &aAction;
53 }
EDA_BASE_FRAME * GetEditFrame() const
Definition: tool_manager.h:256
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, EDA_BASE_FRAME *aWindow)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:116
std::map< int, const TOOL_ACTION * > m_toolActions
const BITMAP_OPAQUE * GetIcon() const
Returns an icon associated with the action.
Definition: tool_action.h:149
wxString GetDescription() const
Definition: tool_action.cpp:83
TOOL_MANAGER * m_toolManager
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100
The base frame for deriving all KiCad main window classes.
static const int ACTION_ID
Tool items with ID higher than that are considered TOOL_ACTIONs
std::map< int, bool > m_toolKinds

References ACTION_ID, TOOL_ACTION::GetDescription(), TOOL_MANAGER::GetEditFrame(), TOOL_ACTION::GetIcon(), TOOL_ACTION::GetId(), KiScaledBitmap(), m_toolActions, m_toolKinds, and m_toolManager.

Referenced by KICAD_MANAGER_FRAME::RecreateBaseHToolbar(), DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar(), LIB_VIEW_FRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), PL_EDITOR_FRAME::ReCreateHToolbar(), FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar(), CVPCB_MAINFRAME::ReCreateHToolbar(), GERBVIEW_FRAME::ReCreateHToolbar(), LIB_EDIT_FRAME::ReCreateHToolbar(), SCH_EDIT_FRAME::ReCreateHToolbar(), PCB_EDIT_FRAME::ReCreateHToolbar(), KICAD_MANAGER_FRAME::RecreateLauncher(), PCB_EDIT_FRAME::ReCreateMicrowaveVToolbar(), DISPLAY_FOOTPRINTS_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar(), GERBVIEW_FRAME::ReCreateOptToolbar(), LIB_EDIT_FRAME::ReCreateOptToolbar(), SCH_EDIT_FRAME::ReCreateOptToolbar(), PCB_EDIT_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateVToolbar(), PL_EDITOR_FRAME::ReCreateVToolbar(), GERBVIEW_FRAME::ReCreateVToolbar(), LIB_EDIT_FRAME::ReCreateVToolbar(), SCH_EDIT_FRAME::ReCreateVToolbar(), and PCB_EDIT_FRAME::ReCreateVToolbar().

◆ AddButton()

void ACTION_TOOLBAR::AddButton ( const TOOL_ACTION aAction)

Function AddButton() Adds a large button such as used in the Kicad Manager Frame's launch bar.

Parameters
aAction

Definition at line 56 of file action_toolbar.cpp.

57 {
59  int toolId = aAction.GetId() + ACTION_ID;
60 
61  AddTool( toolId, wxEmptyString, KiScaledBitmap( aAction.GetIcon(), editFrame ),
62  aAction.GetName(), wxITEM_NORMAL );
63 
64  m_toolKinds[ toolId ] = false;
65  m_toolActions[ toolId ] = &aAction;
66 }
EDA_BASE_FRAME * GetEditFrame() const
Definition: tool_manager.h:256
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, EDA_BASE_FRAME *aWindow)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:116
std::map< int, const TOOL_ACTION * > m_toolActions
const BITMAP_OPAQUE * GetIcon() const
Returns an icon associated with the action.
Definition: tool_action.h:149
TOOL_MANAGER * m_toolManager
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100
The base frame for deriving all KiCad main window classes.
static const int ACTION_ID
Tool items with ID higher than that are considered TOOL_ACTIONs
std::map< int, bool > m_toolKinds
const std::string & GetName() const
Function GetName() Returns name of the action.
Definition: tool_action.h:78

References ACTION_ID, TOOL_MANAGER::GetEditFrame(), TOOL_ACTION::GetIcon(), TOOL_ACTION::GetId(), TOOL_ACTION::GetName(), KiScaledBitmap(), m_toolActions, m_toolKinds, and m_toolManager.

◆ onToolEvent()

void ACTION_TOOLBAR::onToolEvent ( wxAuiToolBarEvent &  aEvent)
protected

The default tool event handler.

Definition at line 103 of file action_toolbar.cpp.

104 {
105  OPT_TOOL_EVENT evt;
106  wxString menuText;
107 
108  wxEventType type = aEvent.GetEventType();
109 
110  if( type == wxEVT_COMMAND_TOOL_CLICKED && aEvent.GetId() >= ACTION_ID )
111  {
112  const auto it = m_toolActions.find( aEvent.GetId() );
113 
114  if( it != m_toolActions.end() )
115  evt = it->second->MakeEvent();
116  }
117 
118  // forward the action/update event to the TOOL_MANAGER
119  if( evt && m_toolManager )
120  {
121  evt->SetHasPosition( false );
122  m_toolManager->ProcessEvent( *evt );
123  }
124  else
125  {
126  aEvent.Skip();
127  }
128 }
std::map< int, const TOOL_ACTION * > m_toolActions
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
TOOL_MANAGER * m_toolManager
static const int ACTION_ID
Tool items with ID higher than that are considered TOOL_ACTIONs
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:548

References ACTION_ID, m_toolActions, m_toolManager, and TOOL_MANAGER::ProcessEvent().

Referenced by ACTION_TOOLBAR().

◆ SetToolBitmap()

void ACTION_TOOLBAR::SetToolBitmap ( const TOOL_ACTION aAction,
const wxBitmap &  aBitmap 
)

Function SetToolBitmap() Updates the bitmap of a particular tool.

Not icon-based because we use it for the custom-drawn layer pair bitmap.

Definition at line 69 of file action_toolbar.cpp.

70 {
71  int toolId = aAction.GetId() + ACTION_ID;
72  wxAuiToolBar::SetToolBitmap( toolId, aBitmap );
73 
74  // Set the disabled bitmap: we use the disabled bitmap version
75  // of aBitmap.
76  wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
77 
78  if( tb_item )
79  tb_item->SetDisabledBitmap( aBitmap.ConvertToDisabled() );
80 }
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100
static const int ACTION_ID
Tool items with ID higher than that are considered TOOL_ACTIONs

References ACTION_ID, and TOOL_ACTION::GetId().

Referenced by PCB_EDIT_FRAME::PrepareLayerIndicator(), and KICAD_MANAGER_FRAME::RecreateLauncher().

◆ Toggle() [1/2]

void ACTION_TOOLBAR::Toggle ( const TOOL_ACTION aAction,
bool  aState 
)

Applies the default toggle action.

For checked items this is check/uncheck; for non-checked items it's enable/disable.

Definition at line 83 of file action_toolbar.cpp.

84 {
85  int toolId = aAction.GetId() + ACTION_ID;
86 
87  if( m_toolKinds[ toolId ] )
88  ToggleTool( toolId, aState );
89  else
90  EnableTool( toolId, aState );
91 }
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100
static const int ACTION_ID
Tool items with ID higher than that are considered TOOL_ACTIONs
std::map< int, bool > m_toolKinds

References ACTION_ID, TOOL_ACTION::GetId(), and m_toolKinds.

Referenced by DISPLAY_FOOTPRINTS_FRAME::SyncToolbars(), LIB_VIEW_FRAME::SyncToolbars(), KICAD_MANAGER_FRAME::SyncToolbars(), PL_EDITOR_FRAME::SyncToolbars(), FOOTPRINT_EDIT_FRAME::SyncToolbars(), CVPCB_MAINFRAME::SyncToolbars(), LIB_EDIT_FRAME::SyncToolbars(), GERBVIEW_FRAME::SyncToolbars(), PCB_EDIT_FRAME::SyncToolbars(), and SCH_EDIT_FRAME::SyncToolbars().

◆ Toggle() [2/2]

void ACTION_TOOLBAR::Toggle ( const TOOL_ACTION aAction,
bool  aEnabled,
bool  aChecked 
)

Definition at line 94 of file action_toolbar.cpp.

95 {
96  int toolId = aAction.GetId() + ACTION_ID;
97 
98  EnableTool( toolId, aEnabled );
99  ToggleTool( toolId, aEnabled && aChecked );
100 }
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100
static const int ACTION_ID
Tool items with ID higher than that are considered TOOL_ACTIONs

References ACTION_ID, and TOOL_ACTION::GetId().

Member Data Documentation

◆ ACTION_ID

const int ACTION_TOOLBAR::ACTION_ID = 10000
staticprotected

Tool items with ID higher than that are considered TOOL_ACTIONs

Definition at line 87 of file action_toolbar.h.

Referenced by Add(), AddButton(), onToolEvent(), SetToolBitmap(), and Toggle().

◆ m_toolActions

std::map<int, const TOOL_ACTION*> ACTION_TOOLBAR::m_toolActions
protected

Definition at line 91 of file action_toolbar.h.

Referenced by Add(), AddButton(), and onToolEvent().

◆ m_toolKinds

std::map<int, bool> ACTION_TOOLBAR::m_toolKinds
protected

Definition at line 90 of file action_toolbar.h.

Referenced by Add(), AddButton(), and Toggle().

◆ m_toolManager

TOOL_MANAGER* ACTION_TOOLBAR::m_toolManager
protected

Definition at line 89 of file action_toolbar.h.

Referenced by Add(), AddButton(), and onToolEvent().

◆ TOGGLE


The documentation for this class was generated from the following files: