KiCad PCB EDA Suite
gerbview_dialog_display_options_frame.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) 2010-2014 Jean-Pierre Charras jp.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 
27 #include <fctsys.h>
28 #include <common.h>
29 #include <macros.h>
30 #include <class_drawpanel.h>
31 #include <config_map.h>
32 
33 #include <gerbview.h>
34 #include <gerbview_frame.h>
36 
37 #include <class_draw_panel_gal.h>
38 #include <view/view.h>
39 #include <gerbview_painter.h>
42 
43 
44 /*******************************************/
45 /* Dialog frame to select display options */
46 /*******************************************/
48 {
49 private:
53 
54 public:
55 
58 
59 protected:
60  void OnScaleSlider( wxScrollEvent& aEvent ) override;
61  void OnScaleAuto( wxCommandEvent& aEvent ) override;
62  bool TransferDataToWindow() override;
63  bool TransferDataFromWindow() override;
64 
65 private:
66  void OnOKBUttonClick( wxCommandEvent& event ) override;
67  void OnCancelButtonClick( wxCommandEvent& event ) override;
68  void initOptDialog( );
69 };
70 
71 
72 void GERBVIEW_FRAME::InstallGerberOptionsDialog( wxCommandEvent& event )
73 {
74  DIALOG_DISPLAY_OPTIONS dlg( this );
75  int opt = dlg.ShowModal();
76 
77  if( opt > 0 )
78  m_canvas->Refresh();
79 }
80 
81 
83  DIALOG_DISPLAY_OPTIONS_BASE( parent, wxID_ANY ),
84  m_last_scale( -1 )
85 {
86  m_Parent = parent;
87  m_scaleSlider->SetStep( 25 );
88  SetFocus();
89  initOptDialog( );
90 
91  GetSizer()->Fit( this );
92  GetSizer()->SetSizeHints( this );
93  Center();
94  m_sdbSizer1OK->SetDefault();
95 
97 }
98 
99 
100 void DIALOG_DISPLAY_OPTIONS::OnCancelButtonClick( wxCommandEvent& event )
101 {
102  EndModal( 0 );
103 }
104 
105 
107 {
109  m_galOptsPanel = new GAL_OPTIONS_PANEL( this, galOptions );
110  m_UpperSizer->Add( m_galOptsPanel, 0, wxEXPAND, 0 );
112 
114  m_BoxUnits->SetSelection( g_UserUnit ? 1 : 0 );
115 
116  // Show Option Draw Lines. We use DisplayPcbTrackFill as Lines draw option
119 
120  // Show Option Draw polygons
122 
123  m_ShowPageLimits->SetSelection(0);
124 
126  {
127  wxString curPaperType = m_Parent->GetPageSettings().GetType();
128 
129  for( unsigned i = 1; i < DIM( g_GerberPageSizeList ); ++i )
130  {
131  if( g_GerberPageSizeList[i] == curPaperType )
132  {
133  m_ShowPageLimits->SetSelection( i );
134  break;
135  }
136  }
137  }
138 
142 }
143 
144 
145 void DIALOG_DISPLAY_OPTIONS::OnOKBUttonClick( wxCommandEvent& event )
146 {
148  auto displayOptions = (GBR_DISPLAY_OPTIONS*) m_Parent->GetDisplayOptions();
149 
150  bool needs_repaint = false, option;
151 
153  (m_PolarDisplay->GetSelection() == 0) ? false : true;
154  g_UserUnit = (m_BoxUnits->GetSelection() == 0) ? INCHES : MILLIMETRES;
155 
156  option = ( m_OptDisplayLines->GetSelection() == 1 );
157 
159  needs_repaint = true;
160 
162 
163  option = ( m_OptDisplayFlashedItems->GetSelection() == 1 );
164 
166  needs_repaint = true;
167 
169 
170  option = ( m_OptDisplayPolygons->GetSelection() == 1 );
171 
173  needs_repaint = true;
174 
176 
178 
179  int idx = m_ShowPageLimits->GetSelection();
180 
181  m_Parent->SetShowBorderAndTitleBlock( idx > 0 ? true : false );
182 
183  PAGE_INFO pageInfo( g_GerberPageSizeList[idx] );
184 
185  m_Parent->SetPageSettings( pageInfo );
186 
189 
191 
192  // Apply changes to the GAL
193  auto view = m_Parent->GetGalCanvas()->GetView();
194  auto painter = static_cast<KIGFX::GERBVIEW_PAINTER*>( view->GetPainter() );
195  auto settings = static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>( painter->GetSettings() );
196  settings->LoadDisplayOptions( displayOptions );
197  view->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
198 
199  if( needs_repaint )
200  view->UpdateAllItems( KIGFX::REPAINT );
201 
202  m_Parent->GetCanvas()->Refresh();
203 
204  EndModal( 1 );
205 }
206 
207 
209 {
210  const auto parent = static_cast<GERBVIEW_FRAME*>( GetParent() );
211  const int scale_fourths = parent->GetIconScale();
212 
213  if( scale_fourths <= 0 )
214  {
215  m_scaleAuto->SetValue( true );
216  m_scaleSlider->SetValue( 25 * KiIconScale( parent ) );
217  }
218  else
219  {
220  m_scaleAuto->SetValue( false );
221  m_scaleSlider->SetValue( scale_fourths * 25 );
222  }
223 
224  return true;
225 }
226 
227 
229 {
230  const auto parent = static_cast<GERBVIEW_FRAME*>( GetParent() );
231  const int scale_fourths = m_scaleAuto->GetValue() ? -1 : m_scaleSlider->GetValue() / 25;
232 
233  if( parent->GetIconScale() != scale_fourths )
234  parent->SetIconScale( scale_fourths );
235 
236  return true;
237 }
238 
239 
240 void DIALOG_DISPLAY_OPTIONS::OnScaleSlider( wxScrollEvent& aEvent )
241 {
242  m_scaleAuto->SetValue( false );
243  aEvent.Skip();
244 }
245 
246 
247 void DIALOG_DISPLAY_OPTIONS::OnScaleAuto( wxCommandEvent& aEvent )
248 {
249  if( m_scaleAuto->GetValue() )
250  {
251  m_last_scale = m_scaleSlider->GetValue();
252  m_scaleSlider->SetValue( 25 * KiIconScale( GetParent() ) );
253  }
254  else
255  {
256  if( m_last_scale >= 0 )
257  m_scaleSlider->SetValue( m_last_scale );
258  }
259 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
bool m_DisplayPolygonsFill
Option to draw polygons (filled/sketch)
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:924
void OnOKBUttonClick(wxCommandEvent &event) override
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
void SetEnableZoomNoCenter(bool aEnable)
Definition: draw_panel.cpp:685
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:359
void SetPageSettings(const PAGE_INFO &aPageSettings) override
void LoadDisplayOptions(const GBR_DISPLAY_OPTIONS *aOptions)
Function LoadDisplayOptions Loads settings related to display options.
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
bool GetShowBorderAndTitleBlock() const
Definition: draw_frame.h:353
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
bool m_DisplayLinesFill
Option to draw line items (filled/sketch)
Auxiliary rendering target (noncached)
Definition: definitions.h:42
This file contains miscellaneous commonly used macros and functions.
Item is being added to the view.
Definition: view_item.h:60
void OnCancelButtonClick(wxCommandEvent &event) override
bool TransferDataToWindow() override
Load the panel controls from the given opt.
Class GERBVIEW_PAINTER Contains methods for drawing GerbView-specific items.
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:49
Definition: common.h:146
GBR_DISPLAY_OPTIONS m_DisplayOptions
bool m_DisplayFlashedItemsFill
Option to draw flashed items (filled/sketch)
bool GetEnableZoomNoCenter() const
bool m_DisplayPolarCood
Option to display coordinates in status bar in X,Y or Polar coords.
Class GERBVIEW_RENDER_SETTINGS Stores GerbView specific render settings.
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:57
const PAGE_INFO & GetPageSettings() const override
void OnScaleSlider(wxScrollEvent &aEvent) override
void SetElementVisibility(GERBVIEW_LAYER_ID aItemIdVisible, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
bool GetEnableMousewheelPan() const
int GetIconScale() override
Function GetIconScale.
size_t i
Definition: json11.cpp:597
bool IsElementVisible(GERBVIEW_LAYER_ID aItemIdVisible) const
Function IsElementVisible tests whether a given element category is visible.
void SetEnableMousewheelPan(bool aEnable)
Definition: draw_panel.cpp:668
The common library.
void InstallGerberOptionsDialog(wxCommandEvent &event)
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:903
void SetStep(int aSize)
Set the step size.
const wxString & GetType() const
Definition: page_info.h:92
void SetShowBorderAndTitleBlock(bool aShow)
Definition: draw_frame.h:355
virtual void * GetDisplayOptions()
Function GetDisplayOptions A way to pass info to draw functions.
Definition: draw_frame.h:918
const wxChar * g_GerberPageSizeList[]
List of page sizes.
Definition: gerbview.cpp:38
bool TransferDataFromWindow() override
Read the options set in the UI into the given options object.