KiCad PCB EDA Suite
pcbnew/dialogs/dialog_global_edit_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) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <kicad_string.h>
26 #include <board_commit.h>
27 #include <pcb_edit_frame.h>
28 #include <pcb_layer_box_selector.h>
29 #include <board.h>
30 #include <footprint.h>
31 #include <dimension.h>
32 #include <fp_shape.h>
33 #include <pcb_text.h>
34 #include <widgets/unit_binder.h>
35 #include <tool/tool_manager.h>
36 #include <tools/global_edit_tool.h>
38 
39 
40 // Columns of layer classes grid
41 enum
42 {
50 };
51 
52 enum
53 {
61 };
62 
63 
64 static bool g_modifyReferences;
65 static bool g_modifyValues;
66 static bool g_modifyOtherFields;
68 static bool g_modifyBoardText;
70 static bool g_filterByLayer;
72 static bool g_filterByReference;
73 static wxString g_referenceFilter;
74 static bool g_filterByFootprint;
75 static wxString g_footprintFilter;
76 static bool g_filterSelected = false;
77 
78 
80 {
84 
89 
90 public:
93 
94 protected:
95  void OnUpdateUI( wxUpdateUIEvent& event ) override;
96  void OnLayerFilterSelect( wxCommandEvent& event ) override
97  {
98  m_layerFilterOpt->SetValue( true );
99  }
100  void OnReferenceFilterText( wxCommandEvent& event ) override
101  {
102  m_referenceFilterOpt->SetValue( true );
103  }
104  void OnFootprintFilterText( wxCommandEvent& event ) override
105  {
106  m_footprintFilterOpt->SetValue( true );
107  }
108 
109  bool TransferDataToWindow() override;
110  bool TransferDataFromWindow() override;
111 
112  void visitItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem );
113  void processItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem );
114 };
115 
116 
119  m_lineWidth( parent, m_lineWidthLabel, m_LineWidthCtrl, m_lineWidthUnits, true ),
120  m_textWidth( parent, m_SizeXlabel, m_SizeXCtrl, m_SizeXunit, true ),
121  m_textHeight( parent, m_SizeYlabel, m_SizeYCtrl, m_SizeYunit, true ),
122  m_thickness( parent, m_ThicknessLabel, m_ThicknessCtrl, m_ThicknessUnit, true )
123 {
124  m_parent = parent;
125  m_brdSettings = &m_parent->GetDesignSettings();
126 
130 
132  m_LayerCtrl->SetLayersHotkeys( false );
134  m_LayerCtrl->Resync();
135 
136  m_grid->SetCellHighlightPenWidth( 0 );
137  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
138  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
139  m_grid->SetDefaultCellFont( infoFont );
140 
141  m_sdbSizerButtonsOK->SetDefault();
142 
144 }
145 
146 
148 {
149  g_modifyReferences = m_references->GetValue();
150  g_modifyValues = m_values->GetValue();
151  g_modifyOtherFields = m_otherFields->GetValue();
153  g_modifyBoardText = m_boardText->GetValue();
155 
156  g_filterByLayer = m_layerFilterOpt->GetValue();
159  g_referenceFilter = m_referenceFilter->GetValue();
161  g_footprintFilter = m_footprintFilter->GetValue();
163 }
164 
165 
167 {
169  m_selection = selTool->GetSelection();
170 
171  m_references->SetValue( g_modifyReferences );
172  m_values->SetValue( g_modifyValues );
173  m_otherFields->SetValue( g_modifyOtherFields );
175  m_boardText->SetValue( g_modifyBoardText );
177 
178  if( m_layerFilter->SetLayerSelection( g_layerFilter ) != wxNOT_FOUND )
179  m_layerFilterOpt->SetValue( g_filterByLayer );
180 
181  // SetValue() generates events, ChangeValue() does not
182  m_referenceFilter->ChangeValue( g_referenceFilter );
184  m_footprintFilter->ChangeValue( g_footprintFilter );
187 
192  m_Italic->Set3StateValue( wxCHK_UNDETERMINED );
193  m_keepUpright->Set3StateValue( wxCHK_UNDETERMINED );
194  m_Visible->Set3StateValue( wxCHK_UNDETERMINED );
196 
197 #define SET_INT_VALUE( aRow, aCol, aValue ) \
198  m_grid->SetCellValue( aRow, aCol, StringFromValue( GetUserUnits(), aValue, true ) )
199 
200 #define SET_BOOL_VALUE( aRow, aCol, aValue ) \
201  attr = new wxGridCellAttr; \
202  attr->SetRenderer( new wxGridCellBoolRenderer() ); \
203  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); \
204  attr->SetReadOnly(); \
205  m_grid->SetAttr( aRow, aCol, attr ); \
206  m_grid->SetCellValue( aRow, aCol, ( aValue ) ? "1" : "" )
207 
208  const BOARD_DESIGN_SETTINGS& bds = m_parent->GetBoard()->GetDesignSettings();
209  wxGridCellAttr* attr;
210 
211  m_grid->SetCellValue( ROW_SILK, COL_CLASS_NAME, _( "Silk Layers" ) );
212  m_grid->SetCellValue( ROW_COPPER, COL_CLASS_NAME, _( "Copper Layers" ) );
213  m_grid->SetCellValue( ROW_EDGES, COL_CLASS_NAME, _( "Edge Cuts" ) );
214  m_grid->SetCellValue( ROW_COURTYARD, COL_CLASS_NAME, _( "Courtyards" ) );
215  m_grid->SetCellValue( ROW_FAB, COL_CLASS_NAME, _( "Fab Layers" ) );
216  m_grid->SetCellValue( ROW_OTHERS, COL_CLASS_NAME, _( "Other Layers" ) );
217 
218  m_grid->SetCellValue( ROW_HEADER, COL_LINE_THICKNESS, _( "Line Thickness" ) );
225 
226  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_WIDTH, _( "Text Width" ) );
231 
232  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_HEIGHT, _( "Text Height" ) );
237 
238  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_THICKNESS, _( "Text Thickness" ) );
243 
244  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_ITALIC, _( "Italic" ) );
249 
250  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_UPRIGHT, _( "Upright" ) );
255 
256  return true;
257 
258 #undef SET_INT_VALUE
259 #undef SET_BOOL_VALUE
260 }
261 
262 
264 {
269  m_Italic->Enable( m_setToSpecifiedValues->GetValue() );
270  m_Visible->Enable( m_setToSpecifiedValues->GetValue() );
271  m_LayerLabel->Enable( m_setToSpecifiedValues->GetValue() );
272  m_LayerCtrl->Enable( m_setToSpecifiedValues->GetValue() );
273  m_keepUpright->Enable( m_setToSpecifiedValues->GetValue() );
274 }
275 
276 
278 {
279  aCommit.Modify( aItem );
280 
281  EDA_TEXT* textItem = dynamic_cast<EDA_TEXT*>( aItem );
282  FP_TEXT* fpTextItem = dynamic_cast<FP_TEXT*>( aItem );
283  PCB_SHAPE* drawItem = dynamic_cast<PCB_SHAPE*>( aItem );
284  DIMENSION_BASE* dimension = dynamic_cast<DIMENSION_BASE*>( aItem );
285 
286  if( dimension )
287  textItem = &dimension->Text();
288 
289  if( m_setToSpecifiedValues->GetValue() )
290  {
293 
294  if( !m_textWidth.IsIndeterminate() && textItem )
295  textItem->SetTextSize( wxSize( m_textWidth.GetValue(), textItem->GetTextSize().y ) );
296 
297  if( !m_textHeight.IsIndeterminate() && textItem )
298  textItem->SetTextSize( wxSize( textItem->GetTextSize().x, m_textHeight.GetValue() ) );
299 
300  if( !m_thickness.IsIndeterminate() && textItem )
301  textItem->SetTextThickness( m_thickness.GetValue() );
302 
303  if( m_Italic->Get3StateValue() != wxCHK_UNDETERMINED && textItem )
304  textItem->SetItalic( m_Italic->GetValue() );
305 
306  if( m_Visible->Get3StateValue() != wxCHK_UNDETERMINED && textItem )
307  textItem->SetVisible( m_Visible->GetValue() );
308 
309  if( m_keepUpright->Get3StateValue() != wxCHK_UNDETERMINED && fpTextItem )
310  fpTextItem->SetKeepUpright( m_keepUpright->GetValue() );
311 
313  {
314  if( drawItem )
315  drawItem->SetWidth( m_lineWidth.GetValue() );
316 
317  if( dimension )
318  dimension->SetLineThickness( m_lineWidth.GetValue() );
319  }
320  }
321  else
322  {
323  PCB_LAYER_ID layer = aItem->GetLayer();
324 
325  if( textItem )
326  {
327  textItem->SetTextSize( m_brdSettings->GetTextSize( layer ) );
328  textItem->SetTextThickness( m_brdSettings->GetTextThickness( layer ) );
329  textItem->SetItalic( m_brdSettings->GetTextItalic( layer ) );
330  }
331 
332  if( fpTextItem )
333  fpTextItem->SetKeepUpright( m_brdSettings->GetTextUpright( layer ) );
334 
335  if( drawItem )
336  drawItem->SetWidth( m_brdSettings->GetLineThickness( layer ) );
337 
338  if( dimension )
339  dimension->SetLineThickness( m_brdSettings->GetLineThickness( layer ) );
340  }
341 }
342 
343 
345 {
346  if( m_selectedItemsFilter->GetValue() && !m_selection.Contains( aItem ) )
347  return;
348 
350  {
351  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
352  return;
353  }
354 
355  if( m_referenceFilterOpt->GetValue() && !m_referenceFilter->GetValue().IsEmpty() )
356  {
357  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aItem->GetParent() );
358 
359  if( fp )
360  {
361  if( !WildCompareString( m_referenceFilter->GetValue(), fp->GetReference(), false ) )
362  return;
363  }
364  }
365 
366  if( m_footprintFilterOpt->GetValue() && !m_footprintFilter->GetValue().IsEmpty() )
367  {
368  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aItem->GetParent() );
369 
370  if( fp )
371  {
372  if( !WildCompareString( m_footprintFilter->GetValue(), fp->GetFPID().Format(), false ) )
373  return;
374  }
375  }
376 
377  processItem( aCommit, aItem );
378 }
379 
380 
382 {
385  {
386  return false;
387  }
388 
389  BOARD_COMMIT commit( m_parent );
390 
391  // Go through the footprints
392  for( FOOTPRINT* fp : m_parent->GetBoard()->Footprints() )
393  {
394  if( m_references->GetValue() )
395  visitItem( commit, &fp->Reference() );
396 
397  if( m_values->GetValue() )
398  visitItem( commit, &fp->Value() );
399 
400  // Go through all other footprint items
401  for( BOARD_ITEM* boardItem : fp->GraphicalItems() )
402  {
403  if( boardItem->Type() == PCB_FP_TEXT_T )
404  {
405  // We are guaranteed to always get an EDA_TEXT in this statement, but we must
406  // use the dynamic_cast to move through the type tree anyway.
407  const wxString text = dynamic_cast<EDA_TEXT*>( boardItem )->GetText();
408 
409  if( m_references->GetValue() && text == wxT( "${REFERENCE}" ) )
410  visitItem( commit, boardItem );
411  else if( m_values->GetValue() && text == wxT( "${VALUE}" ) )
412  visitItem( commit, boardItem );
413  else if( m_otherFields->GetValue() )
414  visitItem( commit, boardItem );
415  }
416  else if( boardItem->Type() == PCB_FP_SHAPE_T )
417  {
418  if( m_footprintGraphics->GetValue() )
419  visitItem( commit, boardItem );
420  }
421  }
422  }
423 
424  // Go through the PCB text & graphic items
425  for( BOARD_ITEM* boardItem : m_parent->GetBoard()->Drawings() )
426  {
427  KICAD_T itemType = boardItem->Type();
428 
429  if( itemType == PCB_TEXT_T )
430  {
431  if( m_boardText->GetValue() )
432  visitItem( commit, boardItem );
433  }
434  else if( itemType == PCB_SHAPE_T || BaseType( itemType ) == PCB_DIMENSION_T )
435  {
436  if( m_boardGraphics->GetValue() )
437  visitItem( commit, boardItem );
438  }
439  }
440 
441  commit.Push( "Edit text and graphics properties" );
442  m_parent->GetCanvas()->Refresh();
443 
444  return true;
445 }
446 
447 
449 {
450  PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
451  DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS dlg( editFrame );
452 
453  dlg.ShowModal();
454  return 0;
455 }
456 
457 
#define SET_INT_VALUE(aRow, aCol, aValue)
COMMIT & Modify(EDA_ITEM *aItem)
Create an undo entry for an item that has been already modified.
Definition: commit.h:103
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
void visitItem(const SCH_SHEET_PATH &aSheetPath, SCH_ITEM *aItem)
constexpr KICAD_T BaseType(const KICAD_T aType)
Returns the underlying type of the given type.
Definition: typeinfo.h:235
void SetItalic(bool isItalic)
Definition: eda_text.h:186
void SetVisible(bool aVisible)
Definition: eda_text.h:192
class PCB_TEXT, text on a layer
Definition: typeinfo.h:91
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
bool IsIndeterminate() const
Return true if the control holds the indeterminate value (for instance, if it represents a multiple s...
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
int GetTextThickness(PCB_LAYER_ID aLayer) const
Return the default text thickness from the layer class for the given layer.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
bool GetTextUpright(PCB_LAYER_ID aLayer) const
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:119
bool GetTextItalic(PCB_LAYER_ID aLayer) const
int GetLineThickness(PCB_LAYER_ID aLayer) const
Return the default graphic segment thickness from the layer class for the given layer.
wxSize m_TextSize[LAYER_CLASS_COUNT]
LAYER_NUM GetLayerSelection() const
PCB_SELECTION & GetSelection()
Return the set of currently selected items.
PCB_LAYER_ID
A quick note on layer IDs:
int m_TextThickness[LAYER_CLASS_COUNT]
bool WildCompareString(const wxString &pattern, const wxString &string_to_tst, bool case_sensitive)
Compare a string against wild card (* and ?) pattern using the usual rules.
Definition: string.cpp:499
const wxSize & GetTextSize() const
Definition: eda_text.h:245
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
PCB_TEXT & Text()
Definition: dimension.h:209
Generic, UI-independent tool event.
Definition: tool_event.h:173
bool Contains(EDA_ITEM *aItem) const
Definition: selection.h:114
bool m_TextItalic[LAYER_CLASS_COUNT]
const wxString & GetReference() const
Definition: footprint.h:423
int SetLayerSelection(LAYER_NUM layer)
const LIB_ID & GetFPID() const
Definition: footprint.h:190
#define TEXTS_MAX_SIZE
Maximum text size in internal units (10 inches)
Definition: pcbnew.h:32
bool SetLayersHotkeys(bool value)
class DIMENSION_BASE: abstract dimension meta-type
Definition: typeinfo.h:99
int m_LineThickness[LAYER_CLASS_COUNT]
UTF8 Format() const
Definition: lib_id.cpp:233
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
#define TEXTS_MIN_SIZE
Minimum text size in internal units (1 mil)
Definition: pcbnew.h:31
int LAYER_NUM
This can be replaced with int and removed.
void SetUndefinedLayerName(const wxString &aName)
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void SetKeepUpright(bool aKeepUpright)
Definition: fp_text.h:115
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Validate the control against the given range, informing the user of any errors found.
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
#define SET_BOOL_VALUE(aRow, aCol, aValue)
The main frame for Pcbnew.
void SetWidth(int aWidth)
Definition: pcb_shape.h:117
The selection tool: currently supports:
void processItem(const SCH_SHEET_PATH &aSheetPath, SCH_ITEM *aItem)
virtual long long int GetValue()
Return the current value in Internal Units.
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:166
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
void SetLineThickness(int aWidth)
Definition: dimension.h:188
#define INDETERMINATE_ACTION
Definition: base_units.h:49
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:168
Abstract dimension API.
Definition: dimension.h:95
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:90
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:173
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Return the default text size from the layer class for the given layer.
bool m_TextUpright[LAYER_CLASS_COUNT]
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
Container for design settings for a BOARD object.