KiCad PCB EDA Suite
panel_modedit_defaults.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) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <fctsys.h>
25 #include <pcbnew.h>
26 #include <board_design_settings.h>
27 #include <widgets/paged_dialog.h>
28 #include <footprint_edit_frame.h>
29 #include <widgets/wx_grid.h>
30 
31 #include <panel_modedit_defaults.h>
32 
33 
34 // Columns of layer classes grid
35 enum
36 {
42 };
43 
44 enum
45 {
46  ROW_SILK = 0,
51 
53 };
54 
55 
57  PANEL_MODEDIT_DEFAULTS_BASE( aParent->GetTreebook() ),
58  m_brdSettings( aFrame->GetDesignSettings() ),
59  m_frame( aFrame ),
60  m_Parent( aParent )
61 {
62  m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
63 
64  // Work around a bug in wxWidgets where it fails to recalculate the grid height
65  // after changing the default row size
66  m_grid->AppendRows( 1 );
67  m_grid->DeleteRows( m_grid->GetNumberRows() - 1, 1 );
68 
69  m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
70 
71  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
72  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
73  m_staticTextInfo->SetFont( infoFont );
74 }
75 
76 
78 {
79  // destroy GRID_TRICKS before m_grid.
80  m_grid->PopEventHandler( true );
81 }
82 
83 
85 {
86  wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
87 
88 #define SET_MILS_CELL( row, col, val ) \
89  m_grid->SetCellValue( row, col, StringFromValue( m_frame->GetUserUnits(), val, true, true ) )
90 
91 #define DISABLE_CELL( row, col ) \
92  m_grid->SetReadOnly( row, col ); m_grid->SetCellBackgroundColour( row, col, disabledColour );
93 
94  for( int i = 0; i < ROW_COUNT; ++i )
95  {
97 
98  if( i == ROW_EDGES || i == ROW_COURTYARD )
99  {
104  }
105  else
106  {
110  m_grid->SetCellValue( i, COL_TEXT_ITALIC, m_brdSettings.m_TextItalic[ i ] ? "1" : "" );
111 
112  auto attr = new wxGridCellAttr;
113  attr->SetRenderer( new wxGridCellBoolRenderer() );
114  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
115  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
116  m_grid->SetAttr( i, COL_TEXT_ITALIC, attr );
117  }
118  }
119 
120  // Footprint defaults
124 
126  m_choiceLayerValue->SetSelection( m_brdSettings.m_ValueDefaultlayer == F_SilkS ? 0 : 1 );
128 
129  return true;
130 }
131 
132 
133 int PANEL_MODEDIT_DEFAULTS::getGridValue( int aRow, int aCol )
134 {
135  return ValueFromString( m_frame->GetUserUnits(), m_grid->GetCellValue( aRow, aCol ), true );
136 }
137 
138 
140 {
141  if( !m_grid->CommitPendingChanges() )
142  return false;
143 
144  // Test text parameters.
145  for( int row : { ROW_SILK, ROW_COPPER, ROW_OTHERS } )
146  {
147  int textSize = std::min( getGridValue( row, COL_TEXT_WIDTH ),
148  getGridValue( row, COL_TEXT_HEIGHT ) );
149 
150  if( getGridValue( row, COL_TEXT_THICKNESS ) > textSize / 4 )
151  {
152  wxString msg = _( "Text will not be readable with a thickness greater than\n"
153  "1/4 its width or height." );
154  m_Parent->SetError( msg, this, m_grid, row, COL_TEXT_THICKNESS );
155  return false;
156  }
157  }
158 
159  return true;
160 }
161 
162 
164 {
165  if( !validateData() )
166  return false;
167 
168  for( int i = 0; i < ROW_COUNT; ++i )
169  {
171 
172  if( i == ROW_EDGES || i == ROW_COURTYARD )
173  continue;
174 
179  wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_ITALIC ) );
180  }
181 
183 
184  return true;
185 }
wxString m_RefDefaultText
Default ref text on fp creation.
bool m_ValueDefaultVisibility
Default value text visibility on fp creation.
int getGridValue(int aRow, int aCol)
BOARD_DESIGN_SETTINGS m_brdSettings
Class GRID_TRICKS is used to add cut, copy, and paste to an otherwise unmodied wxGrid instance...
Definition: grid_tricks.h:51
int m_ValueDefaultlayer
Default value text layer on fp creation.
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue, bool aUseMils)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application...
Definition: base_units.cpp:409
Definition of class FOOTPRINT_EDIT_FRAME.
wxSize m_TextSize[LAYER_CLASS_COUNT]
int m_TextThickness[LAYER_CLASS_COUNT]
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:284
bool m_TextItalic[LAYER_CLASS_COUNT]
wxString m_ValueDefaultText
Default value text on fp creation.
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:156
int m_LineThickness[LAYER_CLASS_COUNT]
void SetError(const wxString &aMessage, wxWindow *aPage, wxObject *aCtrl, int aRow=-1, int aCol=-1)
void SetDesignSettings(const BOARD_DESIGN_SETTINGS &aSettings) override
#define SET_MILS_CELL(row, col, val)
size_t i
Definition: json11.cpp:597
int m_RefDefaultlayer
Default ref text layer on fp creation.
Class PANEL_MODEDIT_DEFAULTS_BASE.
bool m_RefDefaultVisibility
Default ref text visibility on fp creation.
PANEL_MODEDIT_DEFAULTS(FOOTPRINT_EDIT_FRAME *aFrame, PAGED_DIALOG *aParent)
FOOTPRINT_EDIT_FRAME * m_frame
#define min(a, b)
Definition: auxiliary.h:85
#define DISABLE_CELL(row, col)