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 (C) 1992-2024 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{
64 return *mgr.GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>( "fpedit" );
65}
66
67
69 wxWindow* aParent, UNITS_PROVIDER* aUnitsProvider ) :
70 PANEL_FP_EDITOR_GRAPHICS_DEFAULTS_BASE( aParent ), m_unitProvider( aUnitsProvider ),
71 m_designSettings( GetPgmSettings().m_DesignSettings ),
72 m_dimensionsPanel( std::make_unique<PANEL_SETUP_DIMENSIONS>( this, *m_unitProvider,
73 m_designSettings ) )
74{
75 m_graphicsGrid->SetUnitsProvider( aUnitsProvider );
78
79 m_graphicsGrid->SetDefaultRowSize( m_graphicsGrid->GetDefaultRowSize() + 4 );
80
81 // Work around a bug in wxWidgets where it fails to recalculate the grid height
82 // after changing the default row size
83 m_graphicsGrid->AppendRows( 1 );
84 m_graphicsGrid->DeleteRows( m_graphicsGrid->GetNumberRows() - 1, 1 );
85
86 m_graphicsGrid->PushEventHandler( new GRID_TRICKS( m_graphicsGrid ) );
87
88 GetSizer()->Add( m_dimensionsPanel.get(), 0, wxEXPAND | wxALL, 5 );
89}
90
91
93{
94 // destroy GRID_TRICKS before grids.
95 m_graphicsGrid->PopEventHandler( true );
96}
97
98
100{
101 wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_FRAMEBK );
102
103 auto disableCell = [&]( int row, int col )
104 {
105 m_graphicsGrid->SetReadOnly( row, col );
106 m_graphicsGrid->SetCellBackgroundColour( row, col, disabledColour );
107 };
108
109 for( int i = 0; i < ROW_COUNT; ++i )
110 {
113
114 if( i == ROW_EDGES || i == ROW_COURTYARD )
115 {
116 disableCell( i, COL_TEXT_WIDTH );
117 disableCell( i, COL_TEXT_HEIGHT );
118 disableCell( i, COL_TEXT_THICKNESS );
119 disableCell( i, COL_TEXT_ITALIC );
120 }
121 else
122 {
124 aCfg->m_DesignSettings.m_TextSize[i].x );
126 aCfg->m_DesignSettings.m_TextSize[i].y );
129 m_graphicsGrid->SetCellValue( i, COL_TEXT_ITALIC,
130 aCfg->m_DesignSettings.m_TextItalic[i] ? wxT( "1" )
131 : wxT( "" ) );
132
133 auto attr = new wxGridCellAttr;
134 attr->SetRenderer( new wxGridCellBoolRenderer() );
135 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
136 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
137 m_graphicsGrid->SetAttr( i, COL_TEXT_ITALIC, attr );
138 }
139 }
140
141 for( int col = 0; col < m_graphicsGrid->GetNumberCols(); col++ )
142 {
143 // Set the minimal width to the column label size.
144 m_graphicsGrid->SetColMinimalWidth( col,
145 m_graphicsGrid->GetVisibleWidth( col, true, false ) );
146
147 // Set the width to see the full contents
148 if( m_graphicsGrid->IsColShown( col ) )
149 m_graphicsGrid->SetColSize( col,
150 m_graphicsGrid->GetVisibleWidth( col, true, true, true ) );
151 }
152
153 m_graphicsGrid->SetRowLabelSize( m_graphicsGrid->GetVisibleWidth( -1, true, true, true ) );
154
155 m_dimensionsPanel->LoadFromSettings( aCfg->m_DesignSettings );
156
157 Layout();
158}
159
160
162{
164
165 loadFPSettings( &cfg );
166
167 return true;
168}
169
170
172{
173 bool retVal = wxPanel::Show( aShow );
174
175 if( aShow && m_firstShow )
176 {
177 m_graphicsGrid->SetColSize( 0, m_graphicsGrid->GetColSize( 0 ) + 1 );
178 m_firstShow = false;
179 }
180
181 return retVal;
182}
183
184
186{
188 return false;
189
191
192 // A minimal value for sizes and thickness:
193 const int minWidth = pcbIUScale.mmToIU( MINIMUM_LINE_WIDTH_MM );
194 const int maxWidth = pcbIUScale.mmToIU( MAXIMUM_LINE_WIDTH_MM );
196 const int maxSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
197 wxString errorsMsg;
198
199 for( int i = 0; i < ROW_COUNT; ++i )
200 {
201 bool badParam = false;
202
203 int lineWidth = m_graphicsGrid->GetUnitValue( i, COL_LINE_THICKNESS );
204
205 if( lineWidth < minWidth || lineWidth > maxWidth )
206 {
207 if( !errorsMsg.IsEmpty() )
208 errorsMsg += wxT( "\n\n" );
209
210 errorsMsg += wxString::Format( _( "%s: Incorrect line width.\n"
211 "It must be between %s and %s" ),
212 m_graphicsGrid->GetRowLabelValue( i ),
213 m_unitProvider->StringFromValue( minWidth, true ),
214 m_unitProvider->StringFromValue( maxWidth, true ) );
215 badParam = true;
216 }
217
218 if( !badParam )
219 cfg.m_LineThickness[i] = lineWidth;
220
221 if( i == ROW_EDGES || i == ROW_COURTYARD )
222 continue;
223
224 badParam = false;
225 int textWidth = m_graphicsGrid->GetUnitValue( i, COL_TEXT_WIDTH );
226 int textHeight = m_graphicsGrid->GetUnitValue( i, COL_TEXT_HEIGHT );
227 int textThickness = m_graphicsGrid->GetUnitValue( i, COL_TEXT_THICKNESS );
228
229 if( textWidth < minSize || textHeight < minSize || textWidth > maxSize
230 || textHeight > maxSize )
231 {
232 if( !errorsMsg.IsEmpty() )
233 errorsMsg += wxT( "\n\n" );
234
235 errorsMsg += wxString::Format( _( "%s: Text size is incorrect.\n"
236 "Size must be between %s and %s" ),
237 m_graphicsGrid->GetRowLabelValue( i ),
239 m_unitProvider->StringFromValue( maxSize, true ) );
240 badParam = true;
241 }
242
243 // Text thickness cannot be > text size /4 to be readable
244 int textMinDim = std::min( textWidth, textHeight );
245 int textMaxThickness = std::min( maxWidth, textMinDim / 4 );
246
247 if( !badParam && ( textThickness < minWidth || textThickness > textMaxThickness ) )
248 {
249 if( !errorsMsg.IsEmpty() )
250 errorsMsg += wxT( "\n\n" );
251
252 if( textThickness > textMaxThickness )
253 errorsMsg += wxString::Format(
254 _( "%s: Text thickness is too large.\n"
255 "It will be truncated to %s" ),
256 m_graphicsGrid->GetRowLabelValue( i ),
257 m_unitProvider->StringFromValue( textMaxThickness, true ) );
258
259 else if( textThickness < minWidth )
260 errorsMsg += wxString::Format( _( "%s: Text thickness is too small.\n"
261 "It will be truncated to %s" ),
262 m_graphicsGrid->GetRowLabelValue( i ),
263 m_unitProvider->StringFromValue( minWidth, true ) );
264
265 textThickness = std::min( textThickness, textMaxThickness );
266 textThickness = std::max( textThickness, minWidth );
267 m_graphicsGrid->SetUnitValue( i, COL_TEXT_THICKNESS, textThickness );
268 }
269
270 if( !badParam )
271 {
272 cfg.m_TextSize[i] = VECTOR2I( textWidth, textHeight );
273 cfg.m_TextThickness[i] = textThickness;
274 }
275
276 wxString msg = m_graphicsGrid->GetCellValue( i, COL_TEXT_ITALIC );
277 cfg.m_TextItalic[i] = wxGridCellBoolEditor::IsTrueValue( msg );
278 }
279
280 m_dimensionsPanel->TransferDataFromWindow();
281
282 if( errorsMsg.IsEmpty() )
283 return true;
284
285 KIDIALOG dlg( wxGetTopLevelParent( this ), errorsMsg, KIDIALOG::KD_ERROR,
286 _( "Parameter error" ) );
287 dlg.ShowModal();
288
289 return false;
290}
291
292
294{
296 cfg.Load(); // Loading without a file will init to defaults
297
298 loadFPSettings( &cfg );
299}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
#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:43
@ KD_ERROR
Definition: kidialog.h:46
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.
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
T * GetAppSettings(const wxString &aFilename)
Returns a handle to the a given settings by type If the settings have already been loaded,...
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)
Calculates the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:769
void SetUnitValue(int aRow, int aCol, int aValue)
Set a unitized cell's value.
Definition: wx_grid.cpp:740
int GetUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition: wx_grid.cpp:698
void SetAutoEvalCols(const std::vector< int > &aCols)
Definition: wx_grid.h:124
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:689
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:637
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:47
#define TEXT_MAX_SIZE_MM
Maximum text size in mm (~10 inches)
Definition: eda_text.h:48
This file is part of the common library.
STL namespace.
static FOOTPRINT_EDITOR_SETTINGS & GetPgmSettings()
static FOOTPRINT_EDITOR_SETTINGS & GetPgmSettings()
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691