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 <string_utils.h>
26 #include <board_commit.h>
27 #include <pcb_edit_frame.h>
28 #include <pcb_layer_box_selector.h>
29 #include <pcbnew.h>
30 #include <board.h>
31 #include <board_design_settings.h>
32 #include <footprint.h>
33 #include <pcb_group.h>
34 #include <pcb_dimension.h>
35 #include <fp_shape.h>
36 #include <pcb_text.h>
37 #include <widgets/unit_binder.h>
38 #include <tool/tool_manager.h>
39 #include <tools/global_edit_tool.h>
41 
42 
43 // Columns of layer classes grid
44 enum
45 {
53 };
54 
55 enum
56 {
64 };
65 
66 
67 static bool g_modifyReferences;
68 static bool g_modifyValues;
69 static bool g_modifyOtherFields;
71 static bool g_modifyBoardText;
73 static bool g_filterByLayer;
75 static bool g_filterByReference;
76 static wxString g_referenceFilter;
77 static bool g_filterByFootprint;
78 static wxString g_footprintFilter;
79 static bool g_filterSelected = false;
80 
81 
83 {
87 
92 
93 public:
96 
97 protected:
98  void onActionButtonChange( wxCommandEvent& event ) override;
99  void onSpecifiedValueUpdateUI( wxUpdateUIEvent& event ) override;
100 
101  void OnLayerFilterSelect( wxCommandEvent& event ) override
102  {
103  m_layerFilterOpt->SetValue( true );
104  }
105  void OnReferenceFilterText( wxCommandEvent& event ) override
106  {
107  m_referenceFilterOpt->SetValue( true );
108  }
109  void OnFootprintFilterText( wxCommandEvent& event ) override
110  {
111  m_footprintFilterOpt->SetValue( true );
112  }
113 
114  bool TransferDataToWindow() override;
115  bool TransferDataFromWindow() override;
116 
117  void visitItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem );
118  void processItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem );
119 };
120 
121 
124  m_lineWidth( parent, m_lineWidthLabel, m_LineWidthCtrl, m_lineWidthUnits ),
125  m_textWidth( parent, m_SizeXlabel, m_SizeXCtrl, m_SizeXunit ),
126  m_textHeight( parent, m_SizeYlabel, m_SizeYCtrl, m_SizeYunit ),
127  m_thickness( parent, m_ThicknessLabel, m_ThicknessCtrl, m_ThicknessUnit )
128 {
129  m_parent = parent;
130  m_brdSettings = &m_parent->GetDesignSettings();
131 
135 
137  m_LayerCtrl->SetLayersHotkeys( false );
139  m_LayerCtrl->Resync();
140 
141  m_grid->SetCellHighlightPenWidth( 0 );
142  m_grid->SetDefaultCellFont( KIUI::GetInfoFont( this ) );
143 
144  m_sdbSizerButtonsOK->SetDefault();
145 
147 }
148 
149 
151 {
152  g_modifyReferences = m_references->GetValue();
153  g_modifyValues = m_values->GetValue();
154  g_modifyOtherFields = m_otherFields->GetValue();
156  g_modifyBoardText = m_boardText->GetValue();
158 
159  g_filterByLayer = m_layerFilterOpt->GetValue();
162  g_referenceFilter = m_referenceFilter->GetValue();
164  g_footprintFilter = m_footprintFilter->GetValue();
166 }
167 
168 
170 {
172  m_selection = selTool->GetSelection();
173 
174  m_references->SetValue( g_modifyReferences );
175  m_values->SetValue( g_modifyValues );
176  m_otherFields->SetValue( g_modifyOtherFields );
178  m_boardText->SetValue( g_modifyBoardText );
180 
181  if( m_layerFilter->SetLayerSelection( g_layerFilter ) != wxNOT_FOUND )
182  m_layerFilterOpt->SetValue( g_filterByLayer );
183 
184  // SetValue() generates events, ChangeValue() does not
185  m_referenceFilter->ChangeValue( g_referenceFilter );
187  m_footprintFilter->ChangeValue( g_footprintFilter );
190 
195  m_Italic->Set3StateValue( wxCHK_UNDETERMINED );
196  m_keepUpright->Set3StateValue( wxCHK_UNDETERMINED );
197  m_Visible->Set3StateValue( wxCHK_UNDETERMINED );
199 
200 #define SET_INT_VALUE( aRow, aCol, aValue ) \
201  m_grid->SetCellValue( aRow, aCol, StringFromValue( GetUserUnits(), aValue, true ) )
202 
203 #define SET_BOOL_VALUE( aRow, aCol, aValue ) \
204  attr = new wxGridCellAttr; \
205  attr->SetRenderer( new wxGridCellBoolRenderer() ); \
206  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); \
207  attr->SetReadOnly(); \
208  m_grid->SetAttr( aRow, aCol, attr ); \
209  m_grid->SetCellValue( aRow, aCol, ( aValue ) ? "1" : "" )
210 
211  const BOARD_DESIGN_SETTINGS& bds = m_parent->GetBoard()->GetDesignSettings();
212  wxGridCellAttr* attr;
213 
214  m_grid->SetCellValue( ROW_SILK, COL_CLASS_NAME, _( "Silk Layers" ) );
215  m_grid->SetCellValue( ROW_COPPER, COL_CLASS_NAME, _( "Copper Layers" ) );
216  m_grid->SetCellValue( ROW_EDGES, COL_CLASS_NAME, _( "Edge Cuts" ) );
217  m_grid->SetCellValue( ROW_COURTYARD, COL_CLASS_NAME, _( "Courtyards" ) );
218  m_grid->SetCellValue( ROW_FAB, COL_CLASS_NAME, _( "Fab Layers" ) );
219  m_grid->SetCellValue( ROW_OTHERS, COL_CLASS_NAME, _( "Other Layers" ) );
220 
221  m_grid->SetCellValue( ROW_HEADER, COL_LINE_THICKNESS, _( "Line Thickness" ) );
228 
229  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_WIDTH, _( "Text Width" ) );
234 
235  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_HEIGHT, _( "Text Height" ) );
240 
241  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_THICKNESS, _( "Text Thickness" ) );
246 
247  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_ITALIC, _( "Italic" ) );
252 
253  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_UPRIGHT, _( "Upright" ) );
258 
259  return true;
260 
261 #undef SET_INT_VALUE
262 #undef SET_BOOL_VALUE
263 }
264 
265 
267 {
268  // Update the UNIT_BINDER controls if the action to take is changed
269  bool enable = m_setToSpecifiedValues->GetValue();
270 
271  m_lineWidth.Enable( enable );
272  m_textWidth.Enable( enable );
273  m_textHeight.Enable( enable );
274  m_thickness.Enable( enable );
275 }
276 
277 
279 {
280  // Update the UI for the elements inside the use specified values sizer
281  event.Enable( m_setToSpecifiedValues->GetValue() );
282 }
283 
284 
286 {
287  aCommit.Modify( aItem );
288 
289  EDA_TEXT* textItem = dynamic_cast<EDA_TEXT*>( aItem );
290  FP_TEXT* fpTextItem = dynamic_cast<FP_TEXT*>( aItem );
291  PCB_SHAPE* drawItem = dynamic_cast<PCB_SHAPE*>( aItem );
292  PCB_DIMENSION_BASE* dimension = dynamic_cast<PCB_DIMENSION_BASE*>( aItem );
293 
294  if( dimension )
295  textItem = &dimension->Text();
296 
297  if( m_setToSpecifiedValues->GetValue() )
298  {
301 
302  if( !m_textWidth.IsIndeterminate() && textItem )
303  textItem->SetTextSize( wxSize( m_textWidth.GetValue(), textItem->GetTextSize().y ) );
304 
305  if( !m_textHeight.IsIndeterminate() && textItem )
306  textItem->SetTextSize( wxSize( textItem->GetTextSize().x, m_textHeight.GetValue() ) );
307 
308  if( !m_thickness.IsIndeterminate() && textItem )
309  textItem->SetTextThickness( m_thickness.GetValue() );
310 
311  if( m_Italic->Get3StateValue() != wxCHK_UNDETERMINED && textItem )
312  textItem->SetItalic( m_Italic->GetValue() );
313 
314  if( m_Visible->Get3StateValue() != wxCHK_UNDETERMINED && textItem )
315  textItem->SetVisible( m_Visible->GetValue() );
316 
317  if( m_keepUpright->Get3StateValue() != wxCHK_UNDETERMINED && fpTextItem )
318  fpTextItem->SetKeepUpright( m_keepUpright->GetValue() );
319 
321  {
322  if( drawItem )
323  drawItem->SetWidth( m_lineWidth.GetValue() );
324 
325  if( dimension )
326  dimension->SetLineThickness( m_lineWidth.GetValue() );
327  }
328  }
329  else
330  {
331  PCB_LAYER_ID layer = aItem->GetLayer();
332 
333  if( textItem )
334  {
335  textItem->SetTextSize( m_brdSettings->GetTextSize( layer ) );
336  textItem->SetTextThickness( m_brdSettings->GetTextThickness( layer ) );
337  textItem->SetItalic( m_brdSettings->GetTextItalic( layer ) );
338  }
339 
340  if( fpTextItem )
341  fpTextItem->SetKeepUpright( m_brdSettings->GetTextUpright( layer ) );
342 
343  if( drawItem )
344  drawItem->SetWidth( m_brdSettings->GetLineThickness( layer ) );
345 
346  if( dimension )
347  dimension->SetLineThickness( m_brdSettings->GetLineThickness( layer ) );
348  }
349 }
350 
351 
353 {
354  if( m_selectedItemsFilter->GetValue() )
355  {
356  BOARD_ITEM* candidate = aItem;
357 
358  if( !candidate->IsSelected() )
359  {
360  if( candidate->GetParent() && candidate->GetParent()->Type() == PCB_FOOTPRINT_T )
361  candidate = candidate->GetParent();
362  }
363 
364  if( !candidate->IsSelected() )
365  {
366  candidate = candidate->GetParentGroup();
367 
368  while( candidate && !candidate->IsSelected() )
369  candidate = candidate->GetParentGroup();
370 
371  if( !candidate )
372  return;
373  }
374  }
375 
377  {
378  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
379  return;
380  }
381 
382  if( m_referenceFilterOpt->GetValue() && !m_referenceFilter->GetValue().IsEmpty() )
383  {
384  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aItem->GetParent() );
385 
386  if( fp )
387  {
388  if( !WildCompareString( m_referenceFilter->GetValue(), fp->GetReference(), false ) )
389  return;
390  }
391  }
392 
393  if( m_footprintFilterOpt->GetValue() && !m_footprintFilter->GetValue().IsEmpty() )
394  {
395  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aItem->GetParent() );
396 
397  if( fp )
398  {
399  if( !WildCompareString( m_footprintFilter->GetValue(), fp->GetFPID().Format(), false ) )
400  return;
401  }
402  }
403 
404  processItem( aCommit, aItem );
405 }
406 
407 
409 {
412  {
413  return false;
414  }
415 
416  BOARD_COMMIT commit( m_parent );
417 
418  // Go through the footprints
419  for( FOOTPRINT* fp : m_parent->GetBoard()->Footprints() )
420  {
421  if( m_references->GetValue() )
422  visitItem( commit, &fp->Reference() );
423 
424  if( m_values->GetValue() )
425  visitItem( commit, &fp->Value() );
426 
427  // Go through all other footprint items
428  for( BOARD_ITEM* boardItem : fp->GraphicalItems() )
429  {
430  if( boardItem->Type() == PCB_FP_TEXT_T )
431  {
432  // We are guaranteed to always get an EDA_TEXT in this statement, but we must
433  // use the dynamic_cast to move through the type tree anyway.
434  const wxString text = dynamic_cast<EDA_TEXT*>( boardItem )->GetText();
435 
436  if( m_references->GetValue() && text == wxT( "${REFERENCE}" ) )
437  visitItem( commit, boardItem );
438  else if( m_values->GetValue() && text == wxT( "${VALUE}" ) )
439  visitItem( commit, boardItem );
440  else if( m_otherFields->GetValue() )
441  visitItem( commit, boardItem );
442  }
443  else if( boardItem->Type() == PCB_FP_SHAPE_T )
444  {
445  if( m_footprintGraphics->GetValue() )
446  visitItem( commit, boardItem );
447  }
448  }
449  }
450 
451  // Go through the PCB text & graphic items
452  for( BOARD_ITEM* boardItem : m_parent->GetBoard()->Drawings() )
453  {
454  KICAD_T itemType = boardItem->Type();
455 
456  if( itemType == PCB_TEXT_T )
457  {
458  if( m_boardText->GetValue() )
459  visitItem( commit, boardItem );
460  }
461  else if( itemType == PCB_SHAPE_T || BaseType( itemType ) == PCB_DIMENSION_T )
462  {
463  if( m_boardGraphics->GetValue() )
464  visitItem( commit, boardItem );
465  }
466  }
467 
468  commit.Push( "Edit text and graphics properties" );
469  m_parent->GetCanvas()->Refresh();
470 
471  return true;
472 }
473 
474 
476 {
477  PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
478  DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS dlg( editFrame );
479 
480  dlg.ShowModal();
481  return 0;
482 }
483 
484 
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:91
#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
bool IsSelected() const
Definition: eda_item.h:123
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:192
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
void visitItem(const SCH_SHEET_PATH &aSheetPath, SCH_ITEM *aItem)
PCB_TEXT & Text()
constexpr KICAD_T BaseType(const KICAD_T aType)
Return the underlying type of the given type.
Definition: typeinfo.h:235
void SetItalic(bool isItalic)
Definition: eda_text.h:179
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:141
class PCB_TEXT, text on a layer
Definition: typeinfo.h:91
int LAYER_NUM
This can be replaced with int and removed.
Definition: layer_ids.h:40
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
Abstract dimension API.
Definition: pcb_dimension.h:95
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
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
void SetLineThickness(int aWidth)
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.
virtual void SetVisible(bool aVisible)
Definition: eda_text.h:185
int m_TextThickness[LAYER_CLASS_COUNT]
const wxSize & GetTextSize() const
Definition: eda_text.h:238
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
Generic, UI-independent tool event.
Definition: tool_event.h:152
bool m_TextItalic[LAYER_CLASS_COUNT]
const wxString & GetReference() const
Definition: footprint.h:430
#define _(s)
int SetLayerSelection(LAYER_NUM layer)
const LIB_ID & GetFPID() const
Definition: footprint.h:194
#define TEXTS_MAX_SIZE
Maximum text size in internal units (10 inches)
Definition: pcbnew.h:32
bool SetLayersHotkeys(bool value)
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition: typeinfo.h:99
int m_LineThickness[LAYER_CLASS_COUNT]
UTF8 Format() const
Definition: lib_id.cpp:116
#define TEXTS_MIN_SIZE
Minimum text size in internal units (1 mil)
Definition: pcbnew.h:31
void SetUndefinedLayerName(const wxString &aName)
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
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.
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:64
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)
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
The main frame for Pcbnew.
void SetWidth(int aWidth)
Definition: pcb_shape.h:96
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.
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.
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:159
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
#define INDETERMINATE_ACTION
Definition: base_units.h:48
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:166
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:171
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.
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
Container for design settings for a BOARD object.