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, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <pgm_base.h>
25#include <grid_tricks.h>
26#include <eda_text.h>
29#include <bitmaps.h>
30#include <confirm.h>
31#include <kidialog.h>
32
33
34// Columns of graphics grid
35enum
36{
42};
43
44enum
45{
52
54};
55
56
61
62
64 UNITS_PROVIDER* aUnitsProvider ) :
66 m_unitProvider( aUnitsProvider ),
67 m_designSettings( GetPgmSettings().m_DesignSettings ),
69{
70 m_graphicsGrid->SetUnitsProvider( aUnitsProvider );
71 m_graphicsGrid->SetAutoEvalCols( { COL_LINE_THICKNESS,
75
76 // Work around a bug in wxWidgets where it fails to recalculate the grid height
77 // after changing the default row size
78 m_graphicsGrid->AppendRows( 1 );
79 m_graphicsGrid->DeleteRows( m_graphicsGrid->GetNumberRows() - 1, 1 );
80
81 m_graphicsGrid->PushEventHandler( new GRID_TRICKS( m_graphicsGrid ) );
82
83 GetSizer()->Add( m_dimensionsPanel.get(), 0, wxEXPAND, 5 );
84}
85
86
88{
89 // destroy GRID_TRICKS before grids.
90 m_graphicsGrid->PopEventHandler( true );
91}
92
93
95{
96 wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_FRAMEBK );
97
98 auto disableCell = [&]( int row, int col )
99 {
100 m_graphicsGrid->SetReadOnly( row, col );
101 m_graphicsGrid->SetCellBackgroundColour( row, col, disabledColour );
102 };
103
104 for( int i = 0; i < ROW_COUNT; ++i )
105 {
106 m_graphicsGrid->SetUnitValue( i, COL_LINE_THICKNESS,
108
109 if( i == ROW_EDGES || i == ROW_COURTYARD )
110 {
111 disableCell( i, COL_TEXT_WIDTH );
112 disableCell( i, COL_TEXT_HEIGHT );
113 disableCell( i, COL_TEXT_THICKNESS );
114 disableCell( i, COL_TEXT_ITALIC );
115 }
116 else
117 {
118 m_graphicsGrid->SetUnitValue( i, COL_TEXT_WIDTH,
119 aCfg->m_DesignSettings.m_TextSize[i].x );
120 m_graphicsGrid->SetUnitValue( i, COL_TEXT_HEIGHT,
121 aCfg->m_DesignSettings.m_TextSize[i].y );
122 m_graphicsGrid->SetUnitValue( i, COL_TEXT_THICKNESS,
124 m_graphicsGrid->SetCellValue( i, COL_TEXT_ITALIC,
125 aCfg->m_DesignSettings.m_TextItalic[i] ? wxT( "1" )
126 : wxT( "" ) );
127
128 auto attr = new wxGridCellAttr;
129 attr->SetRenderer( new wxGridCellBoolRenderer() );
130 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
131 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
132 m_graphicsGrid->SetAttr( i, COL_TEXT_ITALIC, attr );
133 }
134 }
135
136 for( int col = 0; col < m_graphicsGrid->GetNumberCols(); col++ )
137 {
138 // Set the minimal width to the column label size.
139 m_graphicsGrid->SetColMinimalWidth( col, m_graphicsGrid->GetVisibleWidth( col, true, false ) );
140
141 // Set the width to see the full contents
142 if( m_graphicsGrid->IsColShown( col ) )
143 m_graphicsGrid->SetColSize( col, m_graphicsGrid->GetVisibleWidth( col, true, true, true ) );
144 }
145
146 m_graphicsGrid->SetRowLabelSize( m_graphicsGrid->GetVisibleWidth( -1, true, true, true ) );
147
148 m_dimensionsPanel->LoadFromSettings( aCfg->m_DesignSettings );
149
150 Layout();
151}
152
153
155{
157
158 loadFPSettings( &cfg );
159
160 return true;
161}
162
163
165{
166 bool retVal = wxPanel::Show( aShow );
167
168 if( aShow && m_firstShow )
169 {
170 m_graphicsGrid->SetColSize( 0, m_graphicsGrid->GetColSize( 0 ) + 1 );
171 m_firstShow = false;
172 }
173
174 return retVal;
175}
176
177
179{
180 if( !m_graphicsGrid->CommitPendingChanges() )
181 return false;
182
184
185 // A minimal value for sizes and thickness:
186 const int minWidth = pcbIUScale.mmToIU( MINIMUM_LINE_WIDTH_MM );
187 const int maxWidth = pcbIUScale.mmToIU( MAXIMUM_LINE_WIDTH_MM );
188 const int minSize = pcbIUScale.mmToIU( TEXT_MIN_SIZE_MM );
189 const int maxSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
190 wxString errorsMsg;
191
192 for( int i = 0; i < ROW_COUNT; ++i )
193 {
194 bool badParam = false;
195
196 int lineWidth = m_graphicsGrid->GetUnitValue( i, COL_LINE_THICKNESS );
197
198 if( lineWidth < minWidth || lineWidth > maxWidth )
199 {
200 if( !errorsMsg.IsEmpty() )
201 errorsMsg += wxT( "\n\n" );
202
203 errorsMsg += wxString::Format( _( "%s: Incorrect line width.\n"
204 "It must be between %s and %s" ),
205 m_graphicsGrid->GetRowLabelValue( i ),
206 m_unitProvider->StringFromValue( minWidth, true ),
207 m_unitProvider->StringFromValue( maxWidth, true ) );
208 badParam = true;
209 }
210
211 if( !badParam )
212 cfg.m_LineThickness[i] = lineWidth;
213
214 if( i == ROW_EDGES || i == ROW_COURTYARD )
215 continue;
216
217 badParam = false;
218 int textWidth = m_graphicsGrid->GetUnitValue( i, COL_TEXT_WIDTH );
219 int textHeight = m_graphicsGrid->GetUnitValue( i, COL_TEXT_HEIGHT );
220 int textThickness = m_graphicsGrid->GetUnitValue( i, COL_TEXT_THICKNESS );
221
222 if( textWidth < minSize || textHeight < minSize || textWidth > maxSize || textHeight > maxSize )
223 {
224 if( !errorsMsg.IsEmpty() )
225 errorsMsg += wxT( "\n\n" );
226
227 errorsMsg += wxString::Format( _( "%s: Text size is incorrect.\n"
228 "Size must be between %s and %s" ),
229 m_graphicsGrid->GetRowLabelValue( i ),
230 m_unitProvider->StringFromValue( minSize, true ),
231 m_unitProvider->StringFromValue( maxSize, true ) );
232 badParam = true;
233 }
234
235 // Text thickness cannot be > text size /4 to be readable
236 int textMinDim = std::min( textWidth, textHeight );
237 int textMaxThickness = std::min( maxWidth, textMinDim / 4 );
238
239 if( !badParam && ( textThickness < minWidth || textThickness > textMaxThickness ) )
240 {
241 if( !errorsMsg.IsEmpty() )
242 errorsMsg += wxT( "\n\n" );
243
244 if( textThickness > textMaxThickness )
245 {
246 errorsMsg += wxString::Format( _( "%s: Text thickness is too large.\n"
247 "It will be truncated to %s" ),
248 m_graphicsGrid->GetRowLabelValue( i ),
249 m_unitProvider->StringFromValue( textMaxThickness, true ) );
250 }
251 else if( textThickness < minWidth )
252 {
253 errorsMsg += wxString::Format( _( "%s: Text thickness is too small.\n"
254 "It will be truncated to %s" ),
255 m_graphicsGrid->GetRowLabelValue( i ),
256 m_unitProvider->StringFromValue( minWidth, true ) );
257 }
258
259 textThickness = std::min( textThickness, textMaxThickness );
260 textThickness = std::max( textThickness, minWidth );
261 m_graphicsGrid->SetUnitValue( i, COL_TEXT_THICKNESS, textThickness );
262 }
263
264 if( !badParam )
265 {
266 cfg.m_TextSize[i] = VECTOR2I( textWidth, textHeight );
267 cfg.m_TextThickness[i] = textThickness;
268 }
269
270 wxString msg = m_graphicsGrid->GetCellValue( i, COL_TEXT_ITALIC );
271 cfg.m_TextItalic[i] = wxGridCellBoolEditor::IsTrueValue( msg );
272 }
273
274 m_dimensionsPanel->TransferDataFromWindow();
275
276 if( errorsMsg.IsEmpty() )
277 return true;
278
279 KIDIALOG dlg( wxGetTopLevelParent( this ), errorsMsg, KIDIALOG::KD_ERROR, _( "Parameter error" ) );
280 dlg.ShowModal();
281
282 return false;
283}
284
285
287{
289 cfg.Load(); // Loading without a file will init to defaults
290
291 loadFPSettings( &cfg );
292}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
#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:57
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:38
@ KD_ERROR
Definition kidialog.h:43
int ShowModal() override
Definition kidialog.cpp:89
PANEL_FP_EDITOR_GRAPHICS_DEFAULTS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
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.
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:56
#define TEXT_MAX_SIZE_MM
Maximum text size in mm (~10 inches)
Definition eda_text.h:57
STL namespace.
static FOOTPRINT_EDITOR_SETTINGS & GetPgmSettings()
static FOOTPRINT_EDITOR_SETTINGS & GetPgmSettings()
see class PGM_BASE
T * GetAppSettings(const char *aFilename)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683