KiCad PCB EDA Suite
eeschema/dialogs/dialog_set_grid.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) 2018 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <dialog_set_grid_base.h>
25 #include <common.h>
26 #include <sch_base_frame.h>
27 #include <class_draw_panel_gal.h>
28 #include <sch_view.h>
30 
31 
33 {
35 
36 public:
37  DIALOG_SET_GRID( SCH_BASE_FRAME* aParent );
38 
39  bool TransferDataFromWindow() override;
40  bool TransferDataToWindow() override;
41 };
42 
43 
45  DIALOG_SET_GRID_BASE( aParent ),
46  m_frame( aParent )
47 {
48  m_sdbSizerOK->SetDefault();
49 
51 }
52 
53 
55 {
56  const GRIDS& gridSizes = m_frame->GetScreen()->GetGrids();
57 
58  for( size_t i = 0; i < gridSizes.size(); i++ )
59  {
60  m_choiceGridSize->Append( wxString::Format( wxT( "%0.1f" ), gridSizes[i].m_Size.x ) );
61 
62  if( gridSizes[i].m_CmdId == m_frame->GetScreen()->GetGridCmdId() )
63  m_choiceGridSize->SetSelection( (int) i );
64  }
65 
66  return true;
67 }
68 
69 
71 {
72  const GRIDS& gridSizes = m_frame->GetScreen()->GetGrids();
73  wxRealPoint gridSize = gridSizes[ (size_t) m_choiceGridSize->GetSelection() ].m_Size;
75 
76  m_frame->GetCanvas()->GetView()->GetGAL()->SetGridSize( VECTOR2D( gridSize ) );
78 
79  return true;
80 }
81 
82 
83 void SCH_BASE_FRAME::OnGridSettings( wxCommandEvent& aEvent )
84 {
85  DIALOG_SET_GRID dlg( this );
86 
87  dlg.ShowModal();
88 
90  GetCanvas()->Refresh();
91 }
KIGFX::SCH_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
DIALOG_SET_GRID(PCB_BASE_FRAME *aParent, const wxArrayString &aGridChoices)
This has no dependencies on calling wxFrame derivative, such as PCB_BASE_FRAME.
Auxiliary rendering target (noncached)
Definition: definitions.h:49
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
std::vector< GRID_TYPE > GRIDS
Definition: base_screen.h:67
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' flag.
Definition: view.h:585
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
const GRIDS & GetGrids() const
Function GetGrids().
Definition: base_screen.h:339
void SetGridSize(const VECTOR2D &aGridSize)
Set the grid size.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
void UpdateStatusBar() override
Update the status bar information.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
size_t i
Definition: json11.cpp:597
void SetLastGridSizeId(int aId)
The common library.
void OnGridSettings(wxCommandEvent &aEvent) override
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
int GetGridCmdId() const
Return the command ID of the currently selected grid.
Definition: base_screen.h:272
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME,...