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,
51 
53 };
54 
55 
57  PCB_EDIT_FRAME* aFrame ) :
58  PANEL_SETUP_TEXT_AND_GRAPHICS_BASE( aParent->GetTreebook() )
59 {
60  m_Parent = aParent;
61  m_Frame = aFrame;
63 
64  m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
65 
66  // Work around a bug in wxWidgets where it fails to recalculate the grid height
67  // after changing the default row size
68  m_grid->AppendRows( 1 );
69  m_grid->DeleteRows( m_grid->GetNumberRows() - 1, 1 );
70 
71  m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
72 }
73 
74 
76 {
77  // destroy GRID_TRICKS before m_grid.
78  m_grid->PopEventHandler( true );
79 }
80 
81 
83 {
84  wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
85 
86 #define SET_MILS_CELL( row, col, val ) \
87  m_grid->SetCellValue( row, col, StringFromValue( m_Frame->GetUserUnits(), val, true, true ) )
88 
89 #define DISABLE_CELL( row, col ) \
90  m_grid->SetReadOnly( row, col ); m_grid->SetCellBackgroundColour( row, col, disabledColour );
91 
92  for( int i = 0; i < ROW_COUNT; ++i )
93  {
95 
96  if( i == ROW_EDGES || i == ROW_COURTYARD )
97  {
103  }
104  else
105  {
109  m_grid->SetCellValue( i, COL_TEXT_ITALIC, m_BrdSettings->m_TextItalic[ i ] ? "1" : "" );
110  m_grid->SetCellValue( i, COL_TEXT_UPRIGHT, m_BrdSettings->m_TextUpright[ 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  attr = new wxGridCellAttr;
119  attr->SetRenderer( new wxGridCellBoolRenderer() );
120  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
121  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
122  m_grid->SetAttr( i, COL_TEXT_UPRIGHT, attr );
123  }
124  }
125 
126  // Work around an issue where wxWidgets doesn't calculate the row width on its own
127  for( int col = 0; col < m_grid->GetNumberCols(); col++ )
128  m_grid->SetColMinimalWidth( col, m_grid->GetVisibleWidth( col, true, true, false ) );
129 
130  m_grid->SetRowLabelSize( m_grid->GetVisibleWidth( -1, true, true, true ) );
131 
132  Layout();
133 
136 
137  return true;
138 }
139 
140 
142 {
143  return ValueFromString( m_Frame->GetUserUnits(), m_grid->GetCellValue( aRow, aCol ), true );
144 }
145 
146 
148 {
149  if( !m_grid->CommitPendingChanges() )
150  return false;
151 
152  // Test text parameters.
153  for( int row : { ROW_SILK, ROW_COPPER, ROW_OTHERS } )
154  {
155  int textSize = std::min( getGridValue( row, COL_TEXT_WIDTH ),
156  getGridValue( row, COL_TEXT_HEIGHT ) );
157 
158  if( getGridValue( row, COL_TEXT_THICKNESS ) > textSize / 4 )
159  {
160  wxString msg = _( "Text will not be readable with a thickness greater than\n"
161  "1/4 its width or height." );
162  m_Parent->SetError( msg, this, m_grid, row, COL_TEXT_THICKNESS );
163  return false;
164  }
165  }
166 
167  return true;
168 }
169 
170 
172 {
173  if( !validateData() )
174  return false;
175 
176  for( int i = 0; i < ROW_COUNT; ++i )
177  {
179 
180  if( i == ROW_EDGES || i == ROW_COURTYARD )
181  continue;
182 
183  m_BrdSettings->m_TextSize[ i ] =
187  wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_ITALIC ) );
189  wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_UPRIGHT ) );
190  }
191 
194 
195  return true;
196 }
197 
198 
200 {
201  if( !m_grid->CommitPendingChanges() )
202  return;
203 
204  BOARD_DESIGN_SETTINGS* savedSettings = m_BrdSettings;
205 
206  m_BrdSettings = &aBoard->GetDesignSettings();
208 
209  m_BrdSettings = savedSettings;
210 }
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:530
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]
#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:172
PANEL_SETUP_TEXT_AND_GRAPHICS(PAGED_DIALOG *aParent, PCB_EDIT_FRAME *aFrame)
int m_LineThickness[LAYER_CLASS_COUNT]
void SetError(const wxString &aMessage, wxWindow *aPage, wxObject *aCtrl, int aRow=-1, int aCol=-1)
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:160
#define _(s)
Definition: 3d_actions.cpp:31
PCB_EDIT_FRAME is the main frame for Pcbnew.
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, bool aUseMils)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:429
#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.
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.