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-2019 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 #include <grid_tricks.h>
31 
32 #include <panel_modedit_defaults.h>
33 
34 
35 // Columns of layer classes grid
36 enum
37 {
43 };
44 
45 enum
46 {
47  ROW_SILK = 0,
52 
54 };
55 
56 
58  PANEL_MODEDIT_DEFAULTS_BASE( aParent->GetTreebook() ),
59  m_brdSettings( aFrame->GetDesignSettings() ),
60  m_frame( aFrame ),
61  m_Parent( aParent )
62 {
63  m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
64 
65  // Work around a bug in wxWidgets where it fails to recalculate the grid height
66  // after changing the default row size
67  m_grid->AppendRows( 1 );
68  m_grid->DeleteRows( m_grid->GetNumberRows() - 1, 1 );
69 
70  m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
71 
72  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
73  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
74  m_staticTextInfo->SetFont( infoFont );
75 }
76 
77 
79 {
80  // destroy GRID_TRICKS before m_grid.
81  m_grid->PopEventHandler( true );
82 }
83 
84 
86 {
87  wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
88 
89 #define SET_MILS_CELL( row, col, val ) \
90  m_grid->SetCellValue( row, col, StringFromValue( m_frame->GetUserUnits(), val, true, true ) )
91 
92 #define DISABLE_CELL( row, col ) \
93  m_grid->SetReadOnly( row, col ); m_grid->SetCellBackgroundColour( row, col, disabledColour );
94 
95  for( int i = 0; i < ROW_COUNT; ++i )
96  {
98 
99  if( i == ROW_EDGES || i == ROW_COURTYARD )
100  {
105  }
106  else
107  {
111  m_grid->SetCellValue( i, COL_TEXT_ITALIC, m_brdSettings.m_TextItalic[ i ] ? "1" : "" );
112 
113  auto attr = new wxGridCellAttr;
114  attr->SetRenderer( new wxGridCellBoolRenderer() );
115  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
116  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
117  m_grid->SetAttr( i, COL_TEXT_ITALIC, attr );
118  }
119  }
120 
121  // Footprint defaults
125 
127  m_choiceLayerValue->SetSelection( m_brdSettings.m_ValueDefaultlayer == F_SilkS ? 0 : 1 );
129 
130  for( int col = 0; col < m_grid->GetNumberCols(); col++ )
131  {
132  // Set the minimal width to the column label size.
133  m_grid->SetColMinimalWidth( col, m_grid->GetVisibleWidth( col, true, false, false ) );
134 
135  // Set the width to see the full contents
136  if( m_grid->IsColShown( col ) )
137  m_grid->SetColSize( col, m_grid->GetVisibleWidth( col, true, true, true ) );
138  }
139 
140  m_grid->SetRowLabelSize( m_grid->GetVisibleWidth( -1, true, true, true ) );
141 
142  Layout();
143 
144  return true;
145 }
146 
147 
148 int PANEL_MODEDIT_DEFAULTS::getGridValue( int aRow, int aCol )
149 {
150  return ValueFromString( m_frame->GetUserUnits(), m_grid->GetCellValue( aRow, aCol ), true );
151 }
152 
153 
155 {
156  if( !m_grid->CommitPendingChanges() )
157  return false;
158 
159  // Test text parameters.
160  for( int row : { ROW_SILK, ROW_COPPER, ROW_OTHERS } )
161  {
162  int textSize = std::min( getGridValue( row, COL_TEXT_WIDTH ),
163  getGridValue( row, COL_TEXT_HEIGHT ) );
164 
165  if( getGridValue( row, COL_TEXT_THICKNESS ) > textSize / 4 )
166  {
167  wxString msg = _( "Text will not be readable with a thickness greater than\n"
168  "1/4 its width or height." );
169  m_Parent->SetError( msg, this, m_grid, row, COL_TEXT_THICKNESS );
170  return false;
171  }
172  }
173 
174  return true;
175 }
176 
177 
179 {
180  if( !validateData() )
181  return false;
182 
183  for( int i = 0; i < ROW_COUNT; ++i )
184  {
186 
187  if( i == ROW_EDGES || i == ROW_COURTYARD )
188  continue;
189 
194  wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_ITALIC ) );
195  }
196 
198 
199  return true;
200 }
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 mouse and command handling (such as cut, copy, and paste) to a WX_GR...
Definition: grid_tricks.h:51
int m_ValueDefaultlayer
Default value text layer on fp creation.
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=false, bool aKeep=true)
Calculates the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:228
wxSize m_TextSize[LAYER_CLASS_COUNT]
int m_TextThickness[LAYER_CLASS_COUNT]
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:172
#define _(s)
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
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
#define SET_MILS_CELL(row, col, val)
size_t i
Definition: json11.cpp:649
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
long long 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:427
#define min(a, b)
Definition: auxiliary.h:85
#define DISABLE_CELL(row, col)