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:
52  int m_last_scale;
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 
151  (m_PolarDisplay->GetSelection() == 0) ? false : true;
152  g_UserUnit = (m_BoxUnits->GetSelection() == 0) ? INCHES : MILLIMETRES;
153 
154  if( m_OptDisplayLines->GetSelection() == 1 )
156  else
158 
159  if( m_OptDisplayFlashedItems->GetSelection() == 1 )
160  {
162  }
163  else
164  {
166  }
167 
168  if( m_OptDisplayPolygons->GetSelection() == 0 )
170  else
172 
174 
175  int idx = m_ShowPageLimits->GetSelection();
176 
177  m_Parent->SetShowBorderAndTitleBlock( idx > 0 ? true : false );
178 
179  PAGE_INFO pageInfo( g_GerberPageSizeList[idx] );
180 
181  m_Parent->SetPageSettings( pageInfo );
182 
185 
187 
188  // Apply changes to the GAL
189  auto view = m_Parent->GetGalCanvas()->GetView();
190  auto painter = static_cast<KIGFX::GERBVIEW_PAINTER*>( view->GetPainter() );
191  auto settings = static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>( painter->GetSettings() );
192  settings->LoadDisplayOptions( displayOptions );
193  view->RecacheAllItems();
194  view->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
195 
196  m_Parent->GetCanvas()->Refresh();
197 
198  EndModal( 1 );
199 }
200 
201 
203 {
204  const auto parent = static_cast<GERBVIEW_FRAME*>( GetParent() );
205  const int scale_fourths = parent->GetIconScale();
206 
207  if( scale_fourths <= 0 )
208  {
209  m_scaleAuto->SetValue( true );
210  m_scaleSlider->SetValue( 25 * KiIconScale( parent ) );
211  }
212  else
213  {
214  m_scaleAuto->SetValue( false );
215  m_scaleSlider->SetValue( scale_fourths * 25 );
216  }
217 
218  return true;
219 }
220 
221 
223 {
224  const auto parent = static_cast<GERBVIEW_FRAME*>( GetParent() );
225  const int scale_fourths = m_scaleAuto->GetValue() ? -1 : m_scaleSlider->GetValue() / 25;
226 
227  if( parent->GetIconScale() != scale_fourths )
228  parent->SetIconScale( scale_fourths );
229 
230  return true;
231 }
232 
233 
234 void DIALOG_DISPLAY_OPTIONS::OnScaleSlider( wxScrollEvent& aEvent )
235 {
236  m_scaleAuto->SetValue( false );
237  aEvent.Skip();
238 }
239 
240 
241 void DIALOG_DISPLAY_OPTIONS::OnScaleAuto( wxCommandEvent& aEvent )
242 {
243  if( m_scaleAuto->GetValue() )
244  {
245  m_last_scale = m_scaleSlider->GetValue();
246  m_scaleSlider->SetValue( 25 * KiIconScale( GetParent() ) );
247  }
248  else
249  {
250  if( m_last_scale >= 0 )
251  m_scaleSlider->SetValue( m_last_scale );
252  }
253 }
#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:888
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:332
void SetEnableZoomNoCenter(bool aEnable)
Definition: draw_panel.cpp:679
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:334
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:328
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.
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: common.h:145
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:56
const PAGE_INFO & GetPageSettings() const override
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
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.
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:662
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:867
void SetStep(int aSize)
Set the step size.
const wxString & GetType() const
void SetShowBorderAndTitleBlock(bool aShow)
Definition: draw_frame.h:330
virtual void * GetDisplayOptions()
Function GetDisplayOptions A way to pass info to draw functions.
Definition: draw_frame.h:882
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.