KiCad PCB EDA Suite
dialog_libedit_options.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) 2009 Wayne Stambaugh <stambaughw@verizon.net>
5  * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
6  * Copyright (C) 1992-2018 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 
30 #include <fctsys.h>
31 #include <base_screen.h>
32 
33 #include <dialog_libedit_options.h>
34 #include <lib_edit_frame.h>
35 
36 
39  m_last_scale( -1 )
40 {
41  m_sdbSizerOK->SetDefault();
42 
43  SetRepeatLabelInc( Parent()->GetRepeatDeltaLabel() );
44  SetItemRepeatStep( Parent()->GetRepeatStep() );
45  SetPinRepeatStep( Parent()->GetRepeatPinStep() );
46 
47  m_scaleSlider->SetStep( 25 );
48 
49  // Now all widgets have the size fixed, call FinishDialogSettings
51 }
52 
53 
54 void DIALOG_LIBEDIT_OPTIONS::OnScaleSlider( wxScrollEvent& aEvent )
55 {
56  m_scaleAuto->SetValue( false );
57 }
58 
59 
60 void DIALOG_LIBEDIT_OPTIONS::OnScaleAuto( wxCommandEvent& aEvent )
61 {
62  if( m_scaleAuto->GetValue() )
63  {
64  m_last_scale = m_scaleSlider->GetValue();
65  m_scaleSlider->SetValue( 25 * KiIconScale( GetParent() ) );
66  }
67  else
68  {
69  if( m_last_scale >= 0 )
70  m_scaleSlider->SetValue( m_last_scale );
71  }
72 }
73 
74 
76 {
77  if( !wxDialog::TransferDataToWindow() )
78  return false;
79 
80  const auto parent = static_cast<LIB_EDIT_FRAME*>( GetParent() );
81  const int scale_fourths = parent->GetIconScale();
82 
83  if( scale_fourths <= 0 )
84  {
85  m_scaleAuto->SetValue( true );
86  m_scaleSlider->SetValue( 25 * KiIconScale( GetParent() ) );
87  }
88  else
89  {
90  m_scaleAuto->SetValue( false );
91  m_scaleSlider->SetValue( scale_fourths * 25 );
92  }
93 
94  return true;
95 }
96 
97 
99 {
100  if( !wxDialog::TransferDataFromWindow() )
101  return false;
102 
103  const int scale_fourths = m_scaleAuto->GetValue() ? -1 : m_scaleSlider->GetValue() / 25;
104  const auto parent = static_cast<LIB_EDIT_FRAME*>( GetParent() );
105 
106  if( parent->GetIconScale() != scale_fourths )
107  parent->SetIconScale( scale_fourths );
108 
109  return true;
110 }
111 
112 
113 void DIALOG_LIBEDIT_OPTIONS::SetGridSizes( const GRIDS& grid_sizes, int grid_id )
114 {
115  wxASSERT( grid_sizes.size() > 0 );
116 
117  int select = wxNOT_FOUND;
118 
119  for( size_t i = 0; i < grid_sizes.size(); i++ )
120  {
121  wxString tmp;
122  tmp.Printf( wxT( "%0.1f" ), grid_sizes[i].m_Size.x );
123  m_choiceGridSize->Append( tmp );
124 
125  if( grid_sizes[i].m_CmdId == grid_id )
126  select = (int) i;
127  }
128 
129  m_choiceGridSize->SetSelection( select );
130 }
void SetRepeatLabelInc(int aValue)
bool TransferDataFromWindow() override
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int KiIconScale(wxWindow *aWindow)
Function KiIconScale Returns the automatic scale factor that would be used for a given window by KiSc...
Definition: bitmap.cpp:88
DIALOG_LIBEDIT_OPTIONS(LIB_EDIT_FRAME *parent)
void SetIconScale(int aScale) override
Function SetIconScale.
void SetItemRepeatStep(wxPoint aValue)
void SetGridSizes(const GRIDS &grid_sizes, int grid_id)
std::vector< GRID_TYPE > GRIDS
Definition: base_screen.h:69
void OnScaleSlider(wxScrollEvent &aEvent) override
Subclass of DIALOG_LIBEDIT_OPTIONS_BASE, which is generated by wxFormBuilder.
Class DIALOG_LIBEDIT_OPTIONS_BASE.
The symbol library editor main window.
void OnScaleAuto(wxCommandEvent &aEvent) override
int GetIconScale() override
Function GetIconScale.
void SetPinRepeatStep(int aValue)
Definition of class LIB_EDIT_FRAME.
void SetStep(int aSize)
Set the step size.
BASE_SCREEN class implementation.