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 
26 #include <common.h>
27 #include <sch_base_frame.h>
28 #include <class_drawpanel.h>
29 #include <class_draw_panel_gal.h>
30 #include <sch_view.h>
32 
33 
34 
36 {
38 
39 public:
40  DIALOG_SET_GRID( SCH_BASE_FRAME* aParent );
41 
42  bool TransferDataFromWindow() override;
43  bool TransferDataToWindow() override;
44 };
45 
46 
48  DIALOG_SET_GRID_BASE( aParent ),
49  m_frame( aParent )
50 {
51  m_sdbSizerOK->SetDefault();
52 
54 }
55 
56 
58 {
59  const GRIDS& gridSizes = m_frame->GetScreen()->GetGrids();
60 
61  for( size_t i = 0; i < gridSizes.size(); i++ )
62  {
63  m_choiceGridSize->Append( wxString::Format( wxT( "%0.1f" ), gridSizes[i].m_Size.x ) );
64 
65  if( gridSizes[i].m_CmdId == m_frame->GetScreen()->GetGridCmdId() )
66  m_choiceGridSize->SetSelection( (int) i );
67  }
68 
69  return true;
70 }
71 
72 
74 {
75  const GRIDS& gridSizes = m_frame->GetScreen()->GetGrids();
76  wxRealPoint gridSize = gridSizes[ (size_t) m_choiceGridSize->GetSelection() ].m_Size;
78 
79  m_frame->GetCanvas()->GetView()->GetGAL()->SetGridSize( VECTOR2D( gridSize ) );
81 
82  return true;
83 }
84 
85 
86 void SCH_BASE_FRAME::OnGridSettings( wxCommandEvent& aEvent )
87 {
88  DIALOG_SET_GRID dlg( this );
89 
90  dlg.ShowModal();
91 }
int GetGridCmdId() const
Return the command ID of the currently selected grid.
Definition: base_screen.h:403
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.
const GRIDS & GetGrids() const
Function GetGrids().
Definition: base_screen.h:472
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:42
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
std::vector< GRID_TYPE > GRIDS
Definition: base_screen.h:69
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target &#39;dirty&#39; flag.
Definition: view.h:596
SCH_DRAW_PANEL * GetCanvas() const override
KIGFX::SCH_VIEW * GetView() const
void SetGridSize(const VECTOR2D &aGridSize)
Set the grid size.
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)
Definition: draw_frame.h:302
The common library.
void OnGridSettings(wxCommandEvent &aEvent) override
Class DIALOG_SET_GRID_BASE.
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME, and SCH_EDIT_FRAME, and it brings in a common way of handling the provided virtual functions for the derived classes.