KiCad PCB EDA Suite
grid_menu.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  * Copyright (C) 2015-2017 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <tool/grid_menu.h>
27 #include <id.h>
28 #include <draw_frame.h>
29 #include <class_base_screen.h>
30 #include <tool/actions.h>
31 #include <bitmaps.h>
32 
33 #include <functional>
34 using namespace std::placeholders;
35 
36 GRID_MENU::GRID_MENU( EDA_DRAW_FRAME* aParent ) : m_parent( aParent )
37 {
38  BASE_SCREEN* screen = aParent->GetScreen();
39 
40  SetTitle( _( "Grid" ) );
41  SetIcon( grid_select_xpm );
42 
43  wxArrayString gridsList;
44  screen->BuildGridsChoiceList( gridsList, g_UserUnit != INCHES );
45 
46  for( unsigned int i = 0; i < gridsList.GetCount(); ++i )
47  {
48  GRID_TYPE& grid = screen->GetGrid( i );
49  Append( grid.m_CmdId, gridsList[i], wxEmptyString, wxITEM_CHECK );
50  }
51 }
52 
53 
54 OPT_TOOL_EVENT GRID_MENU::eventHandler( const wxMenuEvent& aEvent )
55 {
56  OPT_TOOL_EVENT event( ACTIONS::gridPreset.MakeEvent() );
57  intptr_t idx = aEvent.GetId() - ID_POPUP_GRID_SELECT - 1;
58  event->SetParameter( idx );
59 
60  return event;
61 }
62 
63 
65 {
66  for( unsigned int i = 0; i < GetMenuItemCount(); ++i )
67  Check( ID_POPUP_GRID_SELECT + 1 + i, false );
68 
69  // Check the current grid size
70  Check( m_parent->GetScreen()->GetGridCmdId(), true );
71 }
int GetGridCmdId() const
Return the command ID of the currently selected grid.
OPT_TOOL_EVENT eventHandler(const wxMenuEvent &aEvent) override
Event handler stub.
Definition: grid_menu.cpp:54
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:54
int BuildGridsChoiceList(wxArrayString &aGridsList, bool aMmFirst) const
Function BuildGridsChoiceList().
virtual BASE_SCREEN * GetScreen() const
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:347
EDA_DRAW_FRAME * m_parent
Definition: grid_menu.h:46
static TOOL_ACTION gridPreset
Definition: actions.h:67
const GRID_TYPE & GetGrid() const
Return the grid object of the currently selected grid.
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: common.h:144
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
BASE_SCREEN class implementation.
Class GRID_TYPE is for grid arrays.
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the context menu.
void update() override
Update menu state stub.
Definition: grid_menu.cpp:64
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:460
GRID_MENU(EDA_DRAW_FRAME *aParent)
Definition: grid_menu.cpp:36