KiCad PCB EDA Suite
dialog_general_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 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 /* functions relatives to the dialogs opened from the main menu :
30  * Preferences/general
31  * Preferences/display
32  */
33 #include <fctsys.h>
34 #include <class_drawpanel.h>
35 #include <confirm.h>
36 #include <pcbnew.h>
37 #include <pcb_edit_frame.h>
38 #include <board_design_settings.h>
39 #include <kicad_string.h>
40 #include <pcbnew_id.h>
41 #include <class_board.h>
42 #include <collectors.h>
43 #include <pgm_base.h>
44 #include <dialog_general_options.h>
45 #include <widgets/stepped_slider.h>
46 
47 
50  m_last_scale( -1 )
51 {
52  init();
53 
54  m_scaleSlider->SetStep( 25 );
55 
56  GetSizer()->SetSizeHints( this );
57  Center();
58 }
59 
60 
62 {
63  SetFocus();
64  m_sdbSizerOK->SetDefault();
65 
66  m_Board = GetParent()->GetBoard();
67  auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetParent()->GetDisplayOptions();
68 
69  /* Set display options */
70  m_PolarDisplay->SetSelection( displ_opts->m_DisplayPolarCood ? 1 : 0 );
71  m_UnitsSelection->SetSelection( g_UserUnit ? 1 : 0 );
72 
73  wxString rotationAngle;
74  rotationAngle = AngleToStringDegrees( (double)GetParent()->GetRotationAngle() );
75  m_RotationAngle->SetValue( rotationAngle );
76 
77  wxString timevalue;
78  timevalue << GetParent()->GetAutoSaveInterval() / 60;
79  m_SaveTime->SetValue( timevalue );
80 
81  m_DrcOn->SetValue( GetParent()->Settings().m_legacyDrcOn );
83  m_TrackAutodel->SetValue( GetParent()->Settings().m_legacyAutoDeleteOldTrack );
84  m_Track_45_Only_Ctrl->SetValue( GetParent()->Settings().m_legacyUse45DegreeTracks );
85  m_Segments_45_Only_Ctrl->SetValue( GetParent()->Settings().m_use45DegreeGraphicSegments );
86  m_ZoomCenterOpt->SetValue( ! GetParent()->GetCanvas()->GetEnableZoomNoCenter() );
87  m_MousewheelPANOpt->SetValue( GetParent()->GetCanvas()->GetEnableMousewheelPan() );
88  m_AutoPANOpt->SetValue( GetParent()->GetCanvas()->GetEnableAutoPan() );
89  m_Track_DoubleSegm_Ctrl->SetValue( GetParent()->Settings().m_legacyUseTwoSegmentTracks );
90  m_MagneticPadOptCtrl->SetSelection( GetParent()->Settings().m_magneticPads );
91  m_MagneticTrackOptCtrl->SetSelection( GetParent()->Settings().m_magneticTracks );
92  m_UseEditKeyForWidth->SetValue( GetParent()->Settings().m_editActionChangesTrackWidth );
93  m_dragSelects->SetValue( GetParent()->Settings().m_dragSelects );
94 
95  m_Show_Page_Limits->SetValue( GetParent()->ShowPageLimits() );
96 
97  const int scale_fourths = GetParent()->GetIconScale();
98 
99  if( scale_fourths <= 0 )
100  {
101  m_scaleAuto->SetValue( true );
102  m_scaleSlider->SetValue( 25 * KiIconScale( GetParent() ) );
103  }
104  else
105  {
106  m_scaleAuto->SetValue( false );
107  m_scaleSlider->SetValue( scale_fourths * 25 );
108  }
109 
110  m_checkBoxIconsInMenus->SetValue( Pgm().GetUseIconsInMenus() );
111 }
112 
113 
114 void DIALOG_GENERALOPTIONS::OnScaleSlider( wxScrollEvent& aEvent )
115 {
116  m_scaleAuto->SetValue( false );
117  aEvent.Skip();
118 }
119 
120 
121 void DIALOG_GENERALOPTIONS::OnScaleAuto( wxCommandEvent& aEvent )
122 {
123  if( m_scaleAuto->GetValue() )
124  {
125  m_last_scale = m_scaleSlider->GetValue();
126  m_scaleSlider->SetValue( 25 * KiIconScale( GetParent() ) );
127  }
128  else
129  {
130  if( m_last_scale >= 0 )
131  m_scaleSlider->SetValue( m_last_scale );
132  }
133 }
134 
135 
136 void DIALOG_GENERALOPTIONS::OnCancelClick( wxCommandEvent& event )
137 {
138  event.Skip();
139 }
140 
141 
142 void DIALOG_GENERALOPTIONS::OnOkClick( wxCommandEvent& event )
143 {
144  EDA_UNITS_T ii;
145  auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetParent()->GetDisplayOptions();
146 
147  displ_opts->m_DisplayPolarCood = ( m_PolarDisplay->GetSelection() == 0 ) ? false : true;
148  ii = g_UserUnit;
149  g_UserUnit = ( m_UnitsSelection->GetSelection() == 0 ) ? INCHES : MILLIMETRES;
150 
151  if( ii != g_UserUnit )
153 
154  GetParent()->SetAutoSaveInterval( m_SaveTime->GetValue() * 60 );
155  GetParent()->SetRotationAngle( wxRound( 10.0 * wxAtof( m_RotationAngle->GetValue() ) ) );
156 
157  /* Updating the combobox to display the active layer. */
158  GetParent()->Settings().m_legacyDrcOn = m_DrcOn->GetValue();
159 
161  {
163  GetParent()->GetCanvas()->Refresh();
164  GetParent()->OnModify();
165  }
166 
170 
173  GetParent()->GetCanvas()->SetEnableAutoPan( m_AutoPANOpt->GetValue() );
174 
179  GetParent()->Settings().m_dragSelects = m_dragSelects->GetValue();
180 
182 
183  const int scale_fourths = m_scaleAuto->GetValue() ? -1 : m_scaleSlider->GetValue() / 25;
184 
185  if( GetParent()->GetIconScale() != scale_fourths )
186  GetParent()->SetIconScale( scale_fourths );
187 
188  if( Pgm().GetUseIconsInMenus() != m_checkBoxIconsInMenus->GetValue() )
189  {
192  }
193 
194  EndModal( wxID_OK );
195 }
196 
197 
void SetUseIconsInMenus(bool aUseIcons)
True to use menu icons.
Definition: pgm_base.h:327
virtual void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
void SetIconScale(int aScale) override
Function SetIconScale.
void SetElementVisibility(GAL_LAYER_ID aElement, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:338
This file is part of the common library.
void SetEnableZoomNoCenter(bool aEnable)
Definition: draw_panel.cpp:685
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:359
void OnOkClick(wxCommandEvent &event) override
Class BOARD to handle a board.
int GetIconScale() override
Function GetIconScale.
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
MAGNETIC_PAD_OPTION_VALUES m_magneticPads
BOARD * GetBoard() const
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
PCB_EDIT_FRAME * GetParent() const
void OnCancelClick(wxCommandEvent &event) override
void * GetDisplayOptions() override
Function GetDisplayOptions returns the display options current in use Display options are relative to...
static bool m_use45DegreeGraphicSegments
MAGNETIC_PAD_OPTION_VALUES m_magneticTracks
void OnScaleAuto(wxCommandEvent &aEvent) override
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings...
PCB_GENERAL_SETTINGS & Settings()
wxString AngleToStringDegrees(double aAngle)
Function AngleToStringDegrees is a helper to convert the double aAngle (in internal unit) to a string...
Definition: base_units.cpp:415
Definition: common.h:146
void ReCreateMenuBar() override
Function ReCreateMenuBar Creates recreates the menu bar.
MAGNETIC_PAD_OPTION_VALUES
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:57
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
void SetAutoSaveInterval(int aInterval)
DIALOG_GENERALOPTIONS(PCB_EDIT_FRAME *parent)
see class PGM_BASE
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
void SetEnableMousewheelPan(bool aEnable)
Definition: draw_panel.cpp:668
Class DIALOG_GENERALOPTIONS_BOARDEDITOR_BASE.
void OnScaleSlider(wxScrollEvent &aEvent) override
void SetStep(int aSize)
Set the step size.
void SetShowPageLimits(bool aShow)
Definition: draw_frame.h:357
void SetEnableAutoPan(bool aEnable)
Definition: draw_panel.cpp:676
void SetRotationAngle(int aRotationAngle)
Function SetRotationAngle() Sets the angle used for rotate operations.
void ReCreateAuxiliaryToolbar() override
EDA_UNITS_T
Definition: common.h:145
int GetAutoSaveInterval() const