KiCad PCB EDA Suite
panel_setup_text_and_graphics.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) 2018 KiCad Developers, see change_log.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 <base_units.h>
26 #include <pcb_edit_frame.h>
27 #include <board_design_settings.h>
28 #include <widgets/wx_grid.h>
29 #include <grid_tricks.h>
31 
32 
33 // Columns of layer classes grid
34 enum
35 {
42 };
43 
44 enum
45 {
46  ROW_SILK = 0,
52 
54 };
55 
56 
58  PCB_EDIT_FRAME* aFrame ) :
59  PANEL_SETUP_TEXT_AND_GRAPHICS_BASE( aParent->GetTreebook() )
60 {
61  m_Parent = aParent;
62  m_Frame = aFrame;
64 
65  m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
66 
67  // Work around a bug in wxWidgets where it fails to recalculate the grid height
68  // after changing the default row size
69  m_grid->AppendRows( 1 );
70  m_grid->DeleteRows( m_grid->GetNumberRows() - 1, 1 );
71 
72  m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
73 }
74 
75 
77 {
78  // destroy GRID_TRICKS before m_grid.
79  m_grid->PopEventHandler( true );
80 }
81 
82 
84 {
85  wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
86 
87 #define SET_MILS_CELL( row, col, val ) \
88  m_grid->SetCellValue( row, col, StringFromValue( m_Frame->GetUserUnits(), val, true, true ) )
89 
90 #define DISABLE_CELL( row, col ) \
91  m_grid->SetReadOnly( row, col ); m_grid->SetCellBackgroundColour( row, col, disabledColour );
92 
93  for( int i = 0; i < ROW_COUNT; ++i )
94  {
96 
97  if( i == ROW_EDGES || i == ROW_COURTYARD )
98  {
104  }
105  else
106  {
110  m_grid->SetCellValue( i, COL_TEXT_ITALIC, m_BrdSettings->m_TextItalic[ i ] ? "1" : "" );
111  m_grid->SetCellValue( i, COL_TEXT_UPRIGHT, m_BrdSettings->m_TextUpright[ 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  attr = new wxGridCellAttr;
120  attr->SetRenderer( new wxGridCellBoolRenderer() );
121  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
122  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
123  m_grid->SetAttr( i, COL_TEXT_UPRIGHT, attr );
124  }
125  }
126 
127  // Work around an issue where wxWidgets doesn't calculate the row width on its own
128  for( int col = 0; col < m_grid->GetNumberCols(); col++ )
129  m_grid->SetColMinimalWidth( col, m_grid->GetVisibleWidth( col, true, true, false ) );
130 
131  m_grid->SetRowLabelSize( m_grid->GetVisibleWidth( -1, true, true, true ) );
132 
133  Layout();
134 
137 
138  return true;
139 }
140 
141 
143 {
144  return ValueFromString( m_Frame->GetUserUnits(), m_grid->GetCellValue( aRow, aCol ), true );
145 }
146 
147 
149 {
150  if( !m_grid->CommitPendingChanges() )
151  return false;
152 
153  // Test text parameters.
154  for( int row : { ROW_SILK, ROW_COPPER, ROW_FAB, ROW_OTHERS } )
155  {
156  int textSize = std::min( getGridValue( row, COL_TEXT_WIDTH ),
157  getGridValue( row, COL_TEXT_HEIGHT ) );
158 
159  if( getGridValue( row, COL_TEXT_THICKNESS ) > textSize / 4 )
160  {
161  wxString msg = _( "Text will not be readable with a thickness greater than\n"
162  "1/4 its width or height." );
163  m_Parent->SetError( msg, this, m_grid, row, COL_TEXT_THICKNESS );
164  return false;
165  }
166  }
167 
168  return true;
169 }
170 
171 
173 {
174  if( !validateData() )
175  return false;
176 
177  for( int i = 0; i < ROW_COUNT; ++i )
178  {
180 
181  if( i == ROW_EDGES || i == ROW_COURTYARD )
182  continue;
183 
184  m_BrdSettings->m_TextSize[ i ] =
188  wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_ITALIC ) );
190  wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_UPRIGHT ) );
191  }
192 
195 
196  return true;
197 }
198 
199 
201 {
202  if( !m_grid->CommitPendingChanges() )
203  return;
204 
205  BOARD_DESIGN_SETTINGS* savedSettings = m_BrdSettings;
206 
207  m_BrdSettings = &aBoard->GetDesignSettings();
209 
210  m_BrdSettings = savedSettings;
211 }
Implementation of conversion functions that require both schematic and board internal units.
Class PANEL_SETUP_TEXT_AND_GRAPHICS_BASE.
GRID_TRICKS is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GRID ins...
Definition: grid_tricks.h:51
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:551
void SetError(const wxString &aMessage, const wxString &aPageName, int aCtrlId, int aRow=-1, int aCol=-1)
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:230
wxSize m_TextSize[LAYER_CLASS_COUNT]
int m_TextThickness[LAYER_CLASS_COUNT]
#define DISABLE_CELL(row, col)
bool m_TextItalic[LAYER_CLASS_COUNT]
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174
PANEL_SETUP_TEXT_AND_GRAPHICS(PAGED_DIALOG *aParent, PCB_EDIT_FRAME *aFrame)
int m_LineThickness[LAYER_CLASS_COUNT]
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
#define _(s)
Definition: 3d_actions.cpp:33
PCB_EDIT_FRAME is the main frame for Pcbnew.
#define SET_MILS_CELL(row, col, val)
BOARD * GetBoard() const
bool m_TextUpright[LAYER_CLASS_COUNT]
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, bool aUseMils, EDA_DATA_TYPE aType)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:471
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.