KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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 ) :
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( EDA_EVT_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( EDA_EVT_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,
155 m_BrdSettings->m_TextItalic[ i ] ? wxT( "1" ) : wxT( "" ) );
156 m_grid->SetCellValue( i, COL_TEXT_UPRIGHT,
157 m_BrdSettings->m_TextUpright[ i ] ? wxT( "1" ) : wxT( "" ) );
158
159 auto attr = new wxGridCellAttr;
160 attr->SetRenderer( new wxGridCellBoolRenderer() );
161 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
162 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
163 m_grid->SetAttr( i, COL_TEXT_ITALIC, attr );
164
165 attr = new wxGridCellAttr;
166 attr->SetRenderer( new wxGridCellBoolRenderer() );
167 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
168 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
169 m_grid->SetAttr( i, COL_TEXT_UPRIGHT, attr );
170 }
171 }
172
173 // Work around an issue where wxWidgets doesn't calculate the row width on its own
174 for( int col = 0; col < m_grid->GetNumberCols(); col++ )
175 m_grid->SetColMinimalWidth( col, m_grid->GetVisibleWidth( col ) );
176
177 m_grid->SetRowLabelSize( m_grid->GetVisibleWidth( -1, true, true, true ) );
178
179 Layout();
180
181 m_dimensionUnits->SetSelection( static_cast<int>( m_BrdSettings->m_DimensionUnitsMode ) );
182 m_dimensionUnitsFormat->SetSelection( static_cast<int>( m_BrdSettings->m_DimensionUnitsFormat ) );
183 m_dimensionPrecision->SetSelection( static_cast<int>( m_BrdSettings->m_DimensionPrecision ) );
185
186 int position = static_cast<int>( m_BrdSettings->m_DimensionTextPosition );
187 m_dimensionTextPositionMode->SetSelection( position );
188
192
193 return true;
194}
195
196
198{
200 return false;
201
202 for( int i = 0; i < ROW_COUNT; ++i )
203 {
205
206 if( i == ROW_EDGES || i == ROW_COURTYARD )
207 continue;
208
213 wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_ITALIC ) );
215 wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_UPRIGHT ) );
216 }
217
218 // These are all stored in project file, not board, so no need for OnModify()
219
220 int mode = m_dimensionUnits->GetSelection();
221 m_BrdSettings->m_DimensionUnitsMode = static_cast<DIM_UNITS_MODE>( mode );
222 int format = m_dimensionUnitsFormat->GetSelection();
223 m_BrdSettings->m_DimensionUnitsFormat = static_cast<DIM_UNITS_FORMAT>( format );
224 int precision = m_dimensionPrecision->GetSelection();
225 m_BrdSettings->m_DimensionPrecision = static_cast<DIM_PRECISION>( precision );
227 int position = m_dimensionTextPositionMode->GetSelection();
228 m_BrdSettings->m_DimensionTextPosition = static_cast<DIM_TEXT_POSITION>( position );
232
233 return true;
234}
235
236
238{
240 return;
241
242 BOARD_DESIGN_SETTINGS* savedSettings = m_BrdSettings;
243
244 m_BrdSettings = &aBoard->GetDesignSettings();
246
247 m_BrdSettings = savedSettings;
248}
Container for design settings for a BOARD object.
DIM_PRECISION m_DimensionPrecision
Number of digits after the decimal.
DIM_UNITS_FORMAT m_DimensionUnitsFormat
bool m_TextUpright[LAYER_CLASS_COUNT]
int m_TextThickness[LAYER_CLASS_COUNT]
int m_LineThickness[LAYER_CLASS_COUNT]
VECTOR2I 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:271
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:731
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(wxWindow *aParentWindow, 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:546
int GetUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition: wx_grid.cpp:507
void SetAutoEvalCols(const std::vector< int > &aCols)
Definition: wx_grid.h:104
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:498
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:449
#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:62
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:72
DIM_PRECISION
Definition: pcb_dimension.h:47
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588