KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_fp_editor_graphics_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 The 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
25
26#include <pgm_base.h>
29#include <grid_tricks.h>
30#include <eda_text.h>
33#include <bitmaps.h>
34#include <confirm.h>
35#include <kidialog.h>
36
37
38// Columns of graphics grid
39enum
40{
46};
47
48enum
49{
56
58};
59
60
62{
63 return *GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>( "fpedit" );
64}
65
66
68 UNITS_PROVIDER* aUnitsProvider ) :
70 m_unitProvider( aUnitsProvider ),
71 m_designSettings( GetPgmSettings().m_DesignSettings ),
72 m_dimensionsPanel( std::make_unique<PANEL_SETUP_DIMENSIONS>( this, *m_unitProvider, m_designSettings ) )
73{
74 m_graphicsGrid->SetUnitsProvider( aUnitsProvider );
79
80 // Work around a bug in wxWidgets where it fails to recalculate the grid height
81 // after changing the default row size
82 m_graphicsGrid->AppendRows( 1 );
83 m_graphicsGrid->DeleteRows( m_graphicsGrid->GetNumberRows() - 1, 1 );
84
85 m_graphicsGrid->PushEventHandler( new GRID_TRICKS( m_graphicsGrid ) );
86
87 GetSizer()->Add( m_dimensionsPanel.get(), 0, wxEXPAND, 5 );
88}
89
90
92{
93 // destroy GRID_TRICKS before grids.
94 m_graphicsGrid->PopEventHandler( true );
95}
96
97
99{
100 wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_FRAMEBK );
101
102 auto disableCell = [&]( int row, int col )
103 {
104 m_graphicsGrid->SetReadOnly( row, col );
105 m_graphicsGrid->SetCellBackgroundColour( row, col, disabledColour );
106 };
107
108 for( int i = 0; i < ROW_COUNT; ++i )
109 {
112
113 if( i == ROW_EDGES || i == ROW_COURTYARD )
114 {
115 disableCell( i, COL_TEXT_WIDTH );
116 disableCell( i, COL_TEXT_HEIGHT );
117 disableCell( i, COL_TEXT_THICKNESS );
118 disableCell( i, COL_TEXT_ITALIC );
119 }
120 else
121 {
123 aCfg->m_DesignSettings.m_TextSize[i].x );
125 aCfg->m_DesignSettings.m_TextSize[i].y );
128 m_graphicsGrid->SetCellValue( i, COL_TEXT_ITALIC,
129 aCfg->m_DesignSettings.m_TextItalic[i] ? wxT( "1" )
130 : wxT( "" ) );
131
132 auto attr = new wxGridCellAttr;
133 attr->SetRenderer( new wxGridCellBoolRenderer() );
134 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
135 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
136 m_graphicsGrid->SetAttr( i, COL_TEXT_ITALIC, attr );
137 }
138 }
139
140 for( int col = 0; col < m_graphicsGrid->GetNumberCols(); col++ )
141 {
142 // Set the minimal width to the column label size.
143 m_graphicsGrid->SetColMinimalWidth( col, m_graphicsGrid->GetVisibleWidth( col, true, false ) );
144
145 // Set the width to see the full contents
146 if( m_graphicsGrid->IsColShown( col ) )
147 m_graphicsGrid->SetColSize( col, m_graphicsGrid->GetVisibleWidth( col, true, true, true ) );
148 }
149
150 m_graphicsGrid->SetRowLabelSize( m_graphicsGrid->GetVisibleWidth( -1, true, true, true ) );
151
152 m_dimensionsPanel->LoadFromSettings( aCfg->m_DesignSettings );
153
154 Layout();
155}
156
157
159{
161
162 loadFPSettings( &cfg );
163
164 return true;
165}
166
167
169{
170 bool retVal = wxPanel::Show( aShow );
171
172 if( aShow && m_firstShow )
173 {
174 m_graphicsGrid->SetColSize( 0, m_graphicsGrid->GetColSize( 0 ) + 1 );
175 m_firstShow = false;
176 }
177
178 return retVal;
179}
180
181
183{
185 return false;
186
188
189 // A minimal value for sizes and thickness:
190 const int minWidth = pcbIUScale.mmToIU( MINIMUM_LINE_WIDTH_MM );
191 const int maxWidth = pcbIUScale.mmToIU( MAXIMUM_LINE_WIDTH_MM );
193 const int maxSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
194 wxString errorsMsg;
195
196 for( int i = 0; i < ROW_COUNT; ++i )
197 {
198 bool badParam = false;
199
200 int lineWidth = m_graphicsGrid->GetUnitValue( i, COL_LINE_THICKNESS );
201
202 if( lineWidth < minWidth || lineWidth > maxWidth )
203 {
204 if( !errorsMsg.IsEmpty() )
205 errorsMsg += wxT( "\n\n" );
206
207 errorsMsg += wxString::Format( _( "%s: Incorrect line width.\n"
208 "It must be between %s and %s" ),
209 m_graphicsGrid->GetRowLabelValue( i ),
210 m_unitProvider->StringFromValue( minWidth, true ),
211 m_unitProvider->StringFromValue( maxWidth, true ) );
212 badParam = true;
213 }
214
215 if( !badParam )
216 cfg.m_LineThickness[i] = lineWidth;
217
218 if( i == ROW_EDGES || i == ROW_COURTYARD )
219 continue;
220
221 badParam = false;
222 int textWidth = m_graphicsGrid->GetUnitValue( i, COL_TEXT_WIDTH );
223 int textHeight = m_graphicsGrid->GetUnitValue( i, COL_TEXT_HEIGHT );
224 int textThickness = m_graphicsGrid->GetUnitValue( i, COL_TEXT_THICKNESS );
225
226 if( textWidth < minSize || textHeight < minSize || textWidth > maxSize || textHeight > maxSize )
227 {
228 if( !errorsMsg.IsEmpty() )
229 errorsMsg += wxT( "\n\n" );
230
231 errorsMsg += wxString::Format( _( "%s: Text size is incorrect.\n"
232 "Size must be between %s and %s" ),
233 m_graphicsGrid->GetRowLabelValue( i ),
235 m_unitProvider->StringFromValue( maxSize, true ) );
236 badParam = true;
237 }
238
239 // Text thickness cannot be > text size /4 to be readable
240 int textMinDim = std::min( textWidth, textHeight );
241 int textMaxThickness = std::min( maxWidth, textMinDim / 4 );
242
243 if( !badParam && ( textThickness < minWidth || textThickness > textMaxThickness ) )
244 {
245 if( !errorsMsg.IsEmpty() )
246 errorsMsg += wxT( "\n\n" );
247
248 if( textThickness > textMaxThickness )
249 {
250 errorsMsg += wxString::Format( _( "%s: Text thickness is too large.\n"
251 "It will be truncated to %s" ),
252 m_graphicsGrid->GetRowLabelValue( i ),
253 m_unitProvider->StringFromValue( textMaxThickness, true ) );
254 }
255 else if( textThickness < minWidth )
256 {
257 errorsMsg += wxString::Format( _( "%s: Text thickness is too small.\n"
258 "It will be truncated to %s" ),
259 m_graphicsGrid->GetRowLabelValue( i ),
260 m_unitProvider->StringFromValue( minWidth, true ) );
261 }
262
263 textThickness = std::min( textThickness, textMaxThickness );
264 textThickness = std::max( textThickness, minWidth );
265 m_graphicsGrid->SetUnitValue( i, COL_TEXT_THICKNESS, textThickness );
266 }
267
268 if( !badParam )
269 {
270 cfg.m_TextSize[i] = VECTOR2I( textWidth, textHeight );
271 cfg.m_TextThickness[i] = textThickness;
272 }
273
274 wxString msg = m_graphicsGrid->GetCellValue( i, COL_TEXT_ITALIC );
275 cfg.m_TextItalic[i] = wxGridCellBoolEditor::IsTrueValue( msg );
276 }
277
278 m_dimensionsPanel->TransferDataFromWindow();
279
280 if( errorsMsg.IsEmpty() )
281 return true;
282
283 KIDIALOG dlg( wxGetTopLevelParent( this ), errorsMsg, KIDIALOG::KD_ERROR, _( "Parameter error" ) );
284 dlg.ShowModal();
285
286 return false;
287}
288
289
291{
293 cfg.Load(); // Loading without a file will init to defaults
294
295 loadFPSettings( &cfg );
296}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:112
#define MINIMUM_LINE_WIDTH_MM
#define MAXIMUM_LINE_WIDTH_MM
Container for design settings for a BOARD object.
int m_TextThickness[LAYER_CLASS_COUNT]
int m_LineThickness[LAYER_CLASS_COUNT]
VECTOR2I m_TextSize[LAYER_CLASS_COUNT]
bool m_TextItalic[LAYER_CLASS_COUNT]
BOARD_DESIGN_SETTINGS m_DesignSettings
Only some of these settings are actually used for footprint editing.
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
virtual void Load()
Updates the parameters of this object based on the current JSON document contents.
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: kidialog.h:50
@ KD_ERROR
Definition: kidialog.h:53
int ShowModal() override
Definition: kidialog.cpp:95
Class PANEL_FP_EDITOR_GRAPHICS_DEFAULTS_BASE.
std::unique_ptr< PANEL_SETUP_DIMENSIONS > m_dimensionsPanel
void loadFPSettings(const FOOTPRINT_EDITOR_SETTINGS *aCfg)
PANEL_FP_EDITOR_GRAPHICS_DEFAULTS(wxWindow *aParent, UNITS_PROVIDER *aUnitsProvider)
void ResetPanel() override
Reset the contents of this panel.
wxString StringFromValue(double aValue, bool aAddUnitLabel=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
Converts aValue in internal units into a united string.
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=true, bool aKeep=false)
Calculate the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:776
void SetUnitValue(int aRow, int aCol, int aValue)
Set a unitized cell's value.
Definition: wx_grid.cpp:750
int GetUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition: wx_grid.cpp:714
void SetAutoEvalCols(const std::vector< int > &aCols)
Definition: wx_grid.h:128
void SetUnitsProvider(UNITS_PROVIDER *aProvider, int aCol=0)
Set a EUNITS_PROVIDER to enable use of unit- and eval-based Getters.
Definition: wx_grid.cpp:692
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:640
This file is part of the common library.
const int minSize
Push and Shove router track width and via size dialog.
#define _(s)
#define TEXT_MIN_SIZE_MM
Minimum text size (1 micron).
Definition: eda_text.h:46
#define TEXT_MAX_SIZE_MM
Maximum text size in mm (~10 inches)
Definition: eda_text.h:47
This file is part of the common library.
STL namespace.
static FOOTPRINT_EDITOR_SETTINGS & GetPgmSettings()
static FOOTPRINT_EDITOR_SETTINGS & GetPgmSettings()
see class PGM_BASE
constexpr int mmToIU(double mm) const
Definition: base_units.h:92
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695