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-2022 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 <pcb_edit_frame.h>
26#include <widgets/wx_grid.h>
27#include <grid_tricks.h>
29
30#include <wx/treebook.h>
31
32
33// Columns of layer classes grid
34enum
35{
42};
43
44enum
45{
52
54};
55
56
58 PCB_EDIT_FRAME* aFrame ) :
59 PANEL_SETUP_TEXT_AND_GRAPHICS_BASE( aParent->GetTreebook() ),
60 m_arrowLength( aFrame, m_lblArrowLength, m_dimensionArrowLength, m_arrowLengthUnits ),
61 m_extensionOffset( aFrame, m_lblExtensionOffset, m_dimensionExtensionOffset,
62 m_dimensionExtensionOffsetUnits )
63{
64 m_Frame = aFrame;
66
72 m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
73
74 // Work around a bug in wxWidgets where it fails to recalculate the grid height
75 // after changing the default row size
76 m_grid->AppendRows( 1 );
77 m_grid->DeleteRows( m_grid->GetNumberRows() - 1, 1 );
78
79 // Gives a suitable size to m_grid columns
80 // The default wxWidget col size is not very good
81 // Calculate a min best size to handle longest usual numeric values:
82 int min_best_width = m_grid->GetTextExtent( wxT( "555,555555 mils" ) ).x;
83
84 for( int i = 0; i < m_grid->GetNumberCols(); ++i )
85 {
86 // We calculate the column min size only from texts sizes, not using the initial col width
87 // as this initial width is sometimes strange depending on the language (wxGrid bug?)
88 int min_width = m_grid->GetVisibleWidth( i );
89
90 m_grid->SetColMinimalWidth( i, min_width );
91
92 // We use a "best size" >= min_best_width
93 m_grid->SetColSize( i, std::max( min_width, min_best_width ) );
94 }
95
96 m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
97
98 m_Frame->Bind( UNITS_CHANGED, &PANEL_SETUP_TEXT_AND_GRAPHICS::onUnitsChanged, this );
99}
100
101
103{
104 // destroy GRID_TRICKS before m_grid.
105 m_grid->PopEventHandler( true );
106
107 m_Frame->Unbind( UNITS_CHANGED, &PANEL_SETUP_TEXT_AND_GRAPHICS::onUnitsChanged, this );
108}
109
110
112{
113 BOARD_DESIGN_SETTINGS tempBDS( nullptr, "dummy" );
115
116 m_BrdSettings = &tempBDS; // No, address of stack var does not escape function
117
120
121 m_BrdSettings = saveBDS;
122
123 aEvent.Skip();
124}
125
126
128{
129 wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
130
131#define SET_MILS_CELL( row, col, val ) \
132 m_grid->SetCellValue( row, col, m_Frame->StringFromValue( val, true ) )
133
134#define DISABLE_CELL( row, col ) \
135 m_grid->SetReadOnly( row, col ); m_grid->SetCellBackgroundColour( row, col, disabledColour );
136
137 for( int i = 0; i < ROW_COUNT; ++i )
138 {
140
141 if( i == ROW_EDGES || i == ROW_COURTYARD )
142 {
148 }
149 else
150 {
154 m_grid->SetCellValue( i, COL_TEXT_ITALIC, m_BrdSettings->m_TextItalic[ i ] ? wxT( "1" ) : wxT( "" ) );
155 m_grid->SetCellValue( i, COL_TEXT_UPRIGHT, m_BrdSettings->m_TextUpright[ i ] ? wxT( "1" ) : wxT( "" ) );
156
157 auto attr = new wxGridCellAttr;
158 attr->SetRenderer( new wxGridCellBoolRenderer() );
159 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
160 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
161 m_grid->SetAttr( i, COL_TEXT_ITALIC, attr );
162
163 attr = new wxGridCellAttr;
164 attr->SetRenderer( new wxGridCellBoolRenderer() );
165 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
166 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
167 m_grid->SetAttr( i, COL_TEXT_UPRIGHT, attr );
168 }
169 }
170
171 // Work around an issue where wxWidgets doesn't calculate the row width on its own
172 for( int col = 0; col < m_grid->GetNumberCols(); col++ )
173 m_grid->SetColMinimalWidth( col, m_grid->GetVisibleWidth( col ) );
174
175 m_grid->SetRowLabelSize( m_grid->GetVisibleWidth( -1, true, true, true ) );
176
177 Layout();
178
179 wxASSERT_MSG( m_BrdSettings->m_DimensionPrecision <= 4,
180 wxT( "Unhandled dimension precision!" ) );
181
182 int mode = static_cast<int>( m_BrdSettings->m_DimensionUnitsMode );
183 m_dimensionUnits->SetSelection( mode );
184
185 int format = static_cast<int>( m_BrdSettings->m_DimensionUnitsFormat );
186 m_dimensionUnitsFormat->SetSelection( format );
187
190
191 int position = static_cast<int>( m_BrdSettings->m_DimensionTextPosition );
192 m_dimensionTextPositionMode->SetSelection( position );
193
197
198 return true;
199}
200
201
203{
205 return false;
206
207 for( int i = 0; i < ROW_COUNT; ++i )
208 {
210
211 if( i == ROW_EDGES || i == ROW_COURTYARD )
212 continue;
213
218 wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_ITALIC ) );
220 wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_UPRIGHT ) );
221 }
222
223 // These are all stored in project file, not board, so no need for OnModify()
224
225 int mode = m_dimensionUnits->GetSelection();
226 m_BrdSettings->m_DimensionUnitsMode = static_cast<DIM_UNITS_MODE>( mode );
227 int format = m_dimensionUnitsFormat->GetSelection();
228 m_BrdSettings->m_DimensionUnitsFormat = static_cast<DIM_UNITS_FORMAT>( format );
231 int position = m_dimensionTextPositionMode->GetSelection();
232 m_BrdSettings->m_DimensionTextPosition = static_cast<DIM_TEXT_POSITION>( position );
236
237 return true;
238}
239
240
242{
244 return;
245
246 BOARD_DESIGN_SETTINGS* savedSettings = m_BrdSettings;
247
248 m_BrdSettings = &aBoard->GetDesignSettings();
250
251 m_BrdSettings = savedSettings;
252}
Container for design settings for a BOARD object.
DIM_UNITS_FORMAT m_DimensionUnitsFormat
bool m_TextUpright[LAYER_CLASS_COUNT]
int m_DimensionPrecision
Number of digits after the decimal.
int m_TextThickness[LAYER_CLASS_COUNT]
int m_LineThickness[LAYER_CLASS_COUNT]
wxSize m_TextSize[LAYER_CLASS_COUNT]
bool m_TextItalic[LAYER_CLASS_COUNT]
DIM_TEXT_POSITION m_DimensionTextPosition
DIM_UNITS_MODE m_DimensionUnitsMode
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:643
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
Class PANEL_SETUP_TEXT_AND_GRAPHICS_BASE.
PANEL_SETUP_TEXT_AND_GRAPHICS(PAGED_DIALOG *aParent, PCB_EDIT_FRAME *aFrame)
void onUnitsChanged(wxCommandEvent &aEvent)
BOARD * GetBoard() const
The main frame for Pcbnew.
virtual long long int GetValue()
Return the current value in Internal Units.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=true, bool aKeep=false)
Calculates the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:377
int GetUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition: wx_grid.cpp:338
void SetAutoEvalCols(const std::vector< int > &aCols)
Definition: wx_grid.h:90
void SetUnitsProvider(UNITS_PROVIDER *aProvider, int aCol=0)
Set a UNITS_PROVIDER to enable use of unit- and eval-based Getters.
Definition: wx_grid.cpp:329
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:280
#define SET_MILS_CELL(row, col, val)
#define DISABLE_CELL(row, col)
DIM_TEXT_POSITION
Where to place the text on a dimension.
Definition: pcb_dimension.h:48
DIM_UNITS_FORMAT
How to display the units in a dimension's text.
Definition: pcb_dimension.h:40
DIM_UNITS_MODE
Used for storing the units selection in the file because EDA_UNITS alone doesn't cut it.
Definition: pcb_dimension.h:58