KiCad PCB EDA Suite
pcbnew/dialogs/dialog_display_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) 2015 Jean-Pierre Charras, jean-pierre.charras at wanadoo.fr
5  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 /* functions relatives to the dialog opened from the main menu :
22  Preferences/display
23 */
24 
25 #include <fctsys.h>
26 #include <class_drawpanel.h>
27 #include <confirm.h>
28 #include <pcbnew.h>
29 #include <wxPcbStruct.h>
30 #include <pcb_display_options.h>
31 #include <config_map.h>
32 
33 #include <pcbnew_id.h>
34 
35 #include <dialog_display_options.h>
37 
38 #include <class_draw_panel_gal.h>
39 #include <pcb_view.h>
40 #include <pcb_painter.h>
41 
43 
44 
46 {
52 };
53 
54 
55 void PCB_EDIT_FRAME::InstallDisplayOptionsDialog( wxCommandEvent& aEvent )
56 {
57  DIALOG_DISPLAY_OPTIONS dlg( this );
58  dlg.ShowModal();
59 }
60 
61 
64  m_parent( parent ),
65  m_last_scale( -1 )
66 {
68  m_galOptsPanel = new GAL_OPTIONS_PANEL( this, galOptions );
69 
70  sLeftSizer->Add( m_galOptsPanel, 1, wxEXPAND, 0 );
71 
72  m_scaleSlider->SetStep( 25 );
73 
74  SetFocus();
75 
76  m_sdbSizerOK->SetDefault();
77 
78  // Now all widgets have the size fixed, call FinishDialogSettings
80 }
81 
82 
84 {
86 
87  m_OptDisplayTracks->SetValue( displ_opts->m_DisplayPcbTrackFill == SKETCH );
88 
91 
92  m_OptDisplayPads->SetValue( displ_opts->m_DisplayPadFill == SKETCH );
93  m_OptDisplayVias->SetValue( displ_opts->m_DisplayViaFill == SKETCH );
94 
96 
97  m_OptDisplayModTexts->SetValue( displ_opts->m_DisplayModTextFill == SKETCH );
98  m_OptDisplayModOutlines->SetValue( displ_opts->m_DisplayModEdgeFill == SKETCH );
99  m_OptDisplayPadClearence->SetValue( displ_opts->m_DisplayPadIsol );
100  m_OptDisplayPadNumber->SetValue( displ_opts->m_DisplayPadNum );
102  m_OptDisplayDrawings->SetValue( displ_opts->m_DisplayDrawItemsFill == SKETCH );
103  m_ShowNetNamesOption->SetSelection( displ_opts->m_DisplayNetNamesMode );
104 
105  const int scale_fourths = m_parent->GetIconScale();
106 
107  if( scale_fourths <= 0 )
108  {
109  m_scaleAuto->SetValue( true );
110  m_scaleSlider->SetValue( 25 * KiIconScale( m_parent ) );
111  }
112  else
113  {
114  m_scaleAuto->SetValue( false );
115  m_scaleSlider->SetValue( scale_fourths * 25 );
116  }
117 
119 
120  return true;
121 }
122 
123 
124 /*
125  * Update variables with new options
126  */
128 {
130 
132 
133  displ_opts->m_DisplayPcbTrackFill = not m_OptDisplayTracks->GetValue();
134 
137 
138  displ_opts->m_DisplayModTextFill = not m_OptDisplayModTexts->GetValue();
139  displ_opts->m_DisplayModEdgeFill = not m_OptDisplayModOutlines->GetValue();
140 
141  displ_opts->m_DisplayPadFill = not m_OptDisplayPads->GetValue();
142  displ_opts->m_DisplayViaFill = not m_OptDisplayVias->GetValue();
143 
144  displ_opts->m_DisplayPadIsol = m_OptDisplayPadClearence->GetValue();
145 
146  displ_opts->m_DisplayPadNum = m_OptDisplayPadNumber->GetValue();
147 
149  m_OptDisplayPadNoConn->GetValue() );
150 
151  displ_opts->m_DisplayDrawItemsFill = not m_OptDisplayDrawings->GetValue();
152  displ_opts->m_DisplayNetNamesMode = m_ShowNetNamesOption->GetSelection();
153 
155 
156  // Apply changes to the GAL
158  KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view->GetPainter() );
159  KIGFX::PCB_RENDER_SETTINGS* settings =
160  static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
161  settings->LoadDisplayOptions( displ_opts );
162  view->RecacheAllItems();
164 
165  const int scale_fourths = m_scaleAuto->GetValue() ? -1 : m_scaleSlider->GetValue() / 25;
166 
167  if( m_parent->GetIconScale() != scale_fourths )
168  m_parent->SetIconScale( scale_fourths );
169 
170  m_parent->GetCanvas()->Refresh();
171 
172  return true;
173 }
174 
175 
176 void DIALOG_DISPLAY_OPTIONS::OnScaleSlider( wxScrollEvent& aEvent )
177 {
178  m_scaleAuto->SetValue( false );
179  aEvent.Skip();
180 }
181 
182 
183 void DIALOG_DISPLAY_OPTIONS::OnScaleAuto( wxCommandEvent& aEvent )
184 {
185  if( m_scaleAuto->GetValue() )
186  {
187  m_last_scale = m_scaleSlider->GetValue();
188  m_scaleSlider->SetValue( 25 * KiIconScale( GetParent() ) );
189  }
190  else
191  {
192  if( m_last_scale >= 0 )
193  m_scaleSlider->SetValue( m_last_scale );
194  }
195 }
bool ShowPageLimits() const
Definition: draw_frame.h:331
void InstallDisplayOptionsDialog(wxCommandEvent &aEvent)
void SetIconScale(int aScale) override
Function SetIconScale.
Definition: pcbframe.cpp:1297
show a marker on pads with no nets
void SetElementVisibility(GAL_LAYER_ID aElement, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
Definition: pcbframe.cpp:978
void OnScaleAuto(wxCommandEvent &aEvent) override
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Function GetGalDisplayOptions Returns a reference to the gal rendering options used by GAL for render...
Definition: draw_frame.h:888
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:332
This file is part of the common library.
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:334
static const UTIL::CFG_MAP< PCB_DISPLAY_OPTIONS::TRACE_CLEARANCE_DISPLAY_MODE_T > traceClearanceSelectMap
int GetIconScale() override
Function GetIconScale.
Definition: pcbframe.cpp:1289
void RecacheAllItems()
Function RecacheAllItems() Rebuilds GAL display lists.
Definition: view.cpp:1253
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
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
Class PCB_PAINTER Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:186
void * GetDisplayOptions() override
Function GetDisplayOptions returns the display options current in use Display options are relative to...
TRACE_CLEARANCE_DISPLAY_MODE_T m_ShowTrackClearanceMode
How trace clearances are displayed.
Auxiliary rendering target (noncached)
Definition: definitions.h:42
Class PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:62
bool IsElementVisible(GAL_LAYER_ID aElement) const
Function IsElementVisible tests whether a given element category is visible.
Definition: pcbframe.cpp:972
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings...
virtual PCB_RENDER_SETTINGS * GetSettings() override
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
Definition: pcb_painter.h:198
bool TransferDataToWindow() override
Load the panel controls from the given opt.
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' flag.
Definition: view.h:568
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:196
static CFG_NATIVE_VAL< MAP > GetValFromConfig(const MAP &aMap, long aConf)
Get the native value corresponding to the config value (read from file or UI, probably) and find it i...
Definition: config_map.h:96
void LoadDisplayOptions(const PCB_DISPLAY_OPTIONS *aOptions)
Function LoadDisplayOptions Loads settings related to display options (high-contrast mode...
void OnScaleSlider(wxScrollEvent &aEvent) override
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:867
void SetStep(int aSize)
Set the step size.
void SetShowPageLimits(bool aShow)
Definition: draw_frame.h:332
std::vector< std::pair< T, long > > CFG_MAP
A config value table is a list of native values (usually enums) to a different set of values...
Definition: config_map.h:49
Class VIEW.
Definition: view.h:58
Definition of PCB_DISPLAY_OPTIONS class.
static long GetConfigForVal(const MAP &aMap, CFG_NATIVE_VAL< MAP > aVal)
Get the mapped config value (the one to write to file, or use in an index) from the given native (pro...
Definition: config_map.h:69
bool TransferDataFromWindow() override
Read the options set in the UI into the given options object.