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