KiCad PCB EDA Suite
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 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 
25 #include <fctsys.h>
26 #include <base_units.h>
27 #include <class_drawpanel.h>
28 #include <pcb_edit_frame.h>
29 #include <board_design_settings.h>
30 #include <widgets/wx_grid.h>
31 
33 
34 
35 // Columns of layer classes grid
36 enum
37 {
44 };
45 
46 enum
47 {
48  ROW_SILK = 0,
53 
55 };
56 
57 
59  PCB_EDIT_FRAME* aFrame ) :
60  PANEL_SETUP_TEXT_AND_GRAPHICS_BASE( aParent->GetTreebook() )
61 {
62  m_Parent = aParent;
63  m_Frame = aFrame;
65 
66  m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
67 
68  // Work around a bug in wxWidgets where it fails to recalculate the grid height
69  // after changing the default row size
70  m_grid->AppendRows( 1 );
71  m_grid->DeleteRows( m_grid->GetNumberRows() - 1, 1 );
72 
73  m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
74 }
75 
76 
78 {
79  // destroy GRID_TRICKS before m_grid.
80  m_grid->PopEventHandler( true );
81 }
82 
83 
85 {
86  wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
87 
88 #define SET_MILS_CELL( row, col, val ) \
89  m_grid->SetCellValue( row, col, StringFromValue( m_Frame->GetUserUnits(), val, true, true ) )
90 
91 #define DISABLE_CELL( row, col ) \
92  m_grid->SetReadOnly( row, col ); m_grid->SetCellBackgroundColour( row, col, disabledColour );
93 
94  for( int i = 0; i < ROW_COUNT; ++i )
95  {
97 
98  if( i == ROW_EDGES || i == ROW_COURTYARD )
99  {
105  }
106  else
107  {
111  m_grid->SetCellValue( i, COL_TEXT_ITALIC, m_BrdSettings->m_TextItalic[ i ] ? "1" : "" );
112  m_grid->SetCellValue( i, COL_TEXT_UPRIGHT, m_BrdSettings->m_TextUpright[ i ] ? "1" : "" );
113 
114  auto attr = new wxGridCellAttr;
115  attr->SetRenderer( new wxGridCellBoolRenderer() );
116  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
117  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
118  m_grid->SetAttr( i, COL_TEXT_ITALIC, attr );
119 
120  attr = new wxGridCellAttr;
121  attr->SetRenderer( new wxGridCellBoolRenderer() );
122  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
123  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
124  m_grid->SetAttr( i, COL_TEXT_UPRIGHT, attr );
125  }
126  }
127 
128  return true;
129 }
130 
131 
133 {
134  return ValueFromString( m_Frame->GetUserUnits(), m_grid->GetCellValue( aRow, aCol ), true );
135 }
136 
137 
139 {
140  if( !m_grid->CommitPendingChanges() )
141  return false;
142 
143  // Test text parameters.
144  for( int row : { ROW_SILK, ROW_COPPER, ROW_OTHERS } )
145  {
146  int textSize = std::min( getGridValue( row, COL_TEXT_WIDTH ),
147  getGridValue( row, COL_TEXT_HEIGHT ) );
148 
149  if( getGridValue( row, COL_TEXT_THICKNESS ) > textSize / 4 )
150  {
151  wxString msg = _( "Text will not be readable with a thickness greater than\n"
152  "1/4 its width or height." );
153  m_Parent->SetError( msg, this, m_grid, row, COL_TEXT_THICKNESS );
154  return false;
155  }
156  }
157 
158  return true;
159 }
160 
161 
163 {
164  if( !validateData() )
165  return false;
166 
167  for( int i = 0; i < ROW_COUNT; ++i )
168  {
170 
171  if( i == ROW_EDGES || i == ROW_COURTYARD )
172  continue;
173 
178  wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_ITALIC ) );
180  wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_UPRIGHT ) );
181  }
182 
183  return true;
184 }
185 
186 
188 {
189  if( !m_grid->CommitPendingChanges() )
190  return;
191 
192  BOARD_DESIGN_SETTINGS* savedSettings = m_BrdSettings;
193 
194  m_BrdSettings = &aBoard->GetDesignSettings();
196 
197  m_BrdSettings = savedSettings;
198 }
Implementation of conversion functions that require both schematic and board internal units...
Class PANEL_SETUP_TEXT_AND_GRAPHICS_BASE.
Class GRID_TRICKS is used to add cut, copy, and paste to an otherwise unmodied wxGrid instance...
Definition: grid_tricks.h:51
BOARD * GetBoard() const
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue, bool aUseMils)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application...
Definition: base_units.cpp:409
wxSize m_TextSize[LAYER_CLASS_COUNT]
int m_TextThickness[LAYER_CLASS_COUNT]
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:284
#define DISABLE_CELL(row, col)
bool m_TextItalic[LAYER_CLASS_COUNT]
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:538
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:156
PANEL_SETUP_TEXT_AND_GRAPHICS(PAGED_DIALOG *aParent, PCB_EDIT_FRAME *aFrame)
int m_LineThickness[LAYER_CLASS_COUNT]
void SetError(const wxString &aMessage, wxWindow *aPage, wxObject *aCtrl, int aRow=-1, int aCol=-1)
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
size_t i
Definition: json11.cpp:597
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
#define SET_MILS_CELL(row, col, val)
bool m_TextUpright[LAYER_CLASS_COUNT]
#define min(a, b)
Definition: auxiliary.h:85
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.