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 <fctsys.h>
26 #include <kicad_string.h>
27 #include <board_commit.h>
28 #include <pcb_edit_frame.h>
29 #include <pcb_layer_box_selector.h>
30 #include <class_board.h>
31 #include <class_module.h>
32 #include <class_edge_mod.h>
33 #include <class_pcb_text.h>
34 #include <widgets/unit_binder.h>
35 #include <tools/global_edit_tool.h>
37 
38 
39 // Columns of layer classes grid
40 enum
41 {
49 };
50 
51 enum
52 {
60 };
61 
62 
63 static bool g_modifyReferences;
64 static bool g_modifyValues;
65 static bool g_modifyOtherFields;
67 static bool g_modifyBoardText;
69 static bool g_filterByLayer;
71 static bool g_filterByReference;
72 static wxString g_referenceFilter;
73 static bool g_filterByFootprint;
74 static wxString g_footprintFilter;
75 
76 
78 {
81 
86 
87 public:
90 
91 protected:
92  void OnUpdateUI( wxUpdateUIEvent& event ) override;
93  void OnLayerFilterSelect( wxCommandEvent& event ) override
94  {
95  m_layerFilterOpt->SetValue( true );
96  }
97  void OnReferenceFilterText( wxCommandEvent& event ) override
98  {
99  m_referenceFilterOpt->SetValue( true );
100  }
101  void OnFootprintFilterText( wxCommandEvent& event ) override
102  {
103  m_footprintFilterOpt->SetValue( true );
104  }
105 
106  bool TransferDataToWindow() override;
107  bool TransferDataFromWindow() override;
108 
109  void visitItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem );
110  void processItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem );
111 };
112 
113 
116  m_lineWidth( parent, m_lineWidthLabel, m_LineWidthCtrl, m_lineWidthUnits, true ),
117  m_textWidth( parent, m_SizeXlabel, m_SizeXCtrl, m_SizeXunit, true ),
118  m_textHeight( parent, m_SizeYlabel, m_SizeYCtrl, m_SizeYunit, true ),
119  m_thickness( parent, m_ThicknessLabel, m_ThicknessCtrl, m_ThicknessUnit, true )
120 {
121  m_parent = parent;
122  m_brdSettings = &m_parent->GetDesignSettings();
123 
127 
129  m_LayerCtrl->SetLayersHotkeys( false );
131  m_LayerCtrl->Resync();
132 
133  m_grid->SetCellHighlightPenWidth( 0 );
134  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
135  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
136  m_grid->SetDefaultCellFont( infoFont );
137 
138  m_sdbSizerButtonsOK->SetDefault();
139 
141 }
142 
143 
145 {
146  g_modifyReferences = m_references->GetValue();
147  g_modifyValues = m_values->GetValue();
148  g_modifyOtherFields = m_otherFields->GetValue();
150  g_modifyBoardText = m_boardText->GetValue();
152 
153  g_filterByLayer = m_layerFilterOpt->GetValue();
156  g_referenceFilter = m_referenceFilter->GetValue();
158  g_footprintFilter = m_footprintFilter->GetValue();
159 }
160 
161 
163 {
164  m_references->SetValue( g_modifyReferences );
165  m_values->SetValue( g_modifyValues );
166  m_otherFields->SetValue( g_modifyOtherFields );
168  m_boardText->SetValue( g_modifyBoardText );
170 
171  if( m_layerFilter->SetLayerSelection( g_layerFilter ) != wxNOT_FOUND )
172  m_layerFilterOpt->SetValue( g_filterByLayer );
173 
174  // SetValue() generates events, ChangeValue() does not
175  m_referenceFilter->ChangeValue( g_referenceFilter );
177  m_footprintFilter->ChangeValue( g_footprintFilter );
179 
184  m_Italic->Set3StateValue( wxCHK_UNDETERMINED );
185  m_keepUpright->Set3StateValue( wxCHK_UNDETERMINED );
186  m_Visible->Set3StateValue( wxCHK_UNDETERMINED );
188 
189 #define SET_INT_VALUE( aRow, aCol, aValue ) \
190  m_grid->SetCellValue( aRow, aCol, StringFromValue( GetUserUnits(), aValue, true, true ) )
191 
192 #define SET_BOOL_VALUE( aRow, aCol, aValue ) \
193  attr = new wxGridCellAttr; \
194  attr->SetRenderer( new wxGridCellBoolRenderer() ); \
195  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM ); \
196  attr->SetReadOnly(); \
197  m_grid->SetAttr( aRow, aCol, attr ); \
198  m_grid->SetCellValue( aRow, aCol, ( aValue ) ? "1" : "" )
199 
200  const BOARD_DESIGN_SETTINGS& bds = m_parent->GetBoard()->GetDesignSettings();
201  wxGridCellAttr* attr;
202 
203  m_grid->SetCellValue( ROW_SILK, COL_CLASS_NAME, _( "Silk Layers" ) );
204  m_grid->SetCellValue( ROW_COPPER, COL_CLASS_NAME, _( "Copper Layers" ) );
205  m_grid->SetCellValue( ROW_EDGES, COL_CLASS_NAME, _( "Edge Cuts" ) );
206  m_grid->SetCellValue( ROW_COURTYARD, COL_CLASS_NAME, _( "Courtyards" ) );
207  m_grid->SetCellValue( ROW_FAB, COL_CLASS_NAME, _( "Fab Layers" ) );
208  m_grid->SetCellValue( ROW_OTHERS, COL_CLASS_NAME, _( "Other Layers" ) );
209 
210  m_grid->SetCellValue( ROW_HEADER, COL_LINE_THICKNESS, _( "Line Thickness" ) );
217 
218  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_WIDTH, _( "Text Width" ) );
223 
224  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_HEIGHT, _( "Text Height" ) );
229 
230  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_THICKNESS, _( "Text Thickness" ) );
235 
236  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_ITALIC, _( "Italic" ) );
241 
242  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_UPRIGHT, _( "Upright" ) );
247 
248  return true;
249 
250 #undef SET_INT_VALUE
251 #undef SET_BOOL_VALUE
252 }
253 
254 
256 {
261  m_Italic->Enable( m_setToSpecifiedValues->GetValue() );
262  m_Visible->Enable( m_setToSpecifiedValues->GetValue() );
263  m_LayerLabel->Enable( m_setToSpecifiedValues->GetValue() );
264  m_LayerCtrl->Enable( m_setToSpecifiedValues->GetValue() );
265  m_keepUpright->Enable( m_setToSpecifiedValues->GetValue() );
266 }
267 
268 
270 {
271  aCommit.Modify( aItem );
272 
273  auto textItem = dynamic_cast<EDA_TEXT*>( aItem );
274  auto drawItem = dynamic_cast<DRAWSEGMENT*>( aItem );
275  auto moduleTextItem = dyn_cast<TEXTE_MODULE*>( aItem );
276 
277  if( m_setToSpecifiedValues->GetValue() )
278  {
281 
282  if( !m_textWidth.IsIndeterminate() && textItem )
283  textItem->SetTextSize( wxSize( m_textWidth.GetValue(), textItem->GetTextSize().y ) );
284 
285  if( !m_textHeight.IsIndeterminate() && textItem )
286  textItem->SetTextSize( wxSize( textItem->GetTextSize().x, m_textHeight.GetValue() ) );
287 
288  if( !m_thickness.IsIndeterminate() && textItem )
289  textItem->SetTextThickness( m_thickness.GetValue() );
290 
291  if( m_Italic->Get3StateValue() != wxCHK_UNDETERMINED && textItem )
292  textItem->SetItalic( m_Italic->GetValue() );
293 
294  if( m_Visible->Get3StateValue() != wxCHK_UNDETERMINED && textItem )
295  textItem->SetVisible( m_Visible->GetValue() );
296 
297  if( m_keepUpright->Get3StateValue() != wxCHK_UNDETERMINED && moduleTextItem )
298  moduleTextItem->SetKeepUpright( m_keepUpright->GetValue() );
299 
300  if( !m_lineWidth.IsIndeterminate() && drawItem )
301  drawItem->SetWidth( m_lineWidth.GetValue() );
302  }
303  else
304  {
305  PCB_LAYER_ID layer = aItem->GetLayer();
306 
307  if( textItem )
308  {
309  textItem->SetTextSize( m_brdSettings->GetTextSize( layer ) );
310  textItem->SetTextThickness( m_brdSettings->GetTextThickness( layer ) );
311  textItem->SetItalic( m_brdSettings->GetTextItalic( layer ) );
312  }
313 
314  if( moduleTextItem )
315  moduleTextItem->SetKeepUpright( m_brdSettings->GetTextUpright( layer ) );
316 
317  if( drawItem )
318  drawItem->SetWidth( m_brdSettings->GetLineThickness( layer ) );
319  }
320 }
321 
322 
324 {
326  {
327  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
328  return;
329  }
330 
331  if( m_referenceFilterOpt->GetValue() && !m_referenceFilter->GetValue().IsEmpty() )
332  {
333  MODULE* module = dynamic_cast<MODULE*>( aItem->GetParent() );
334 
335  if( module )
336  {
337  if( !WildCompareString( m_referenceFilter->GetValue(), module->GetReference(), false ) )
338  return;
339  }
340  }
341 
342  if( m_footprintFilterOpt->GetValue() && !m_footprintFilter->GetValue().IsEmpty() )
343  {
344  MODULE* module = dynamic_cast<MODULE*>( aItem->GetParent() );
345 
346  if( module )
347  {
348  if( !WildCompareString( m_footprintFilter->GetValue(), module->GetFPID().Format(), false ) )
349  return;
350  }
351  }
352 
353  processItem( aCommit, aItem );
354 }
355 
356 
358 {
361  {
362  return false;
363  }
364 
365  BOARD_COMMIT commit( m_parent );
366 
367  // Go through the modules
368  for( MODULE* module : m_parent->GetBoard()->Modules() )
369  {
370  if( m_references->GetValue() )
371  visitItem( commit, &module->Reference() );
372 
373  if( m_values->GetValue() )
374  visitItem( commit, &module->Value() );
375 
376  // Go through all other module items
377  for( BOARD_ITEM* boardItem : module->GraphicalItems() )
378  {
379  if( boardItem->Type() == PCB_MODULE_TEXT_T )
380  {
381  // We are guaranteed to always get an EDA_TEXT in this statement, but we must
382  // use the dynamic_cast to move through the type tree anyway.
383  const wxString text = dynamic_cast<EDA_TEXT*>( boardItem )->GetText();
384 
385  if( m_references->GetValue() && text == wxT( "${REFERENCE}" ) )
386  visitItem( commit, boardItem );
387  else if( m_values->GetValue() && text == wxT( "${VALUE}" ) )
388  visitItem( commit, boardItem );
389  else if( m_otherFields->GetValue() )
390  visitItem( commit, boardItem );
391  }
392  else if( boardItem->Type() == PCB_MODULE_EDGE_T )
393  {
394  if( m_footprintGraphics->GetValue() )
395  visitItem( commit, boardItem );
396  }
397  }
398  }
399 
400  // Go through the PCB text & graphic items
401  for( BOARD_ITEM* boardItem : m_parent->GetBoard()->Drawings() )
402  {
403  if( boardItem->Type() == PCB_TEXT_T )
404  {
405  if( m_boardText->GetValue() )
406  visitItem( commit, boardItem );
407  }
408  else if( boardItem->Type() == PCB_LINE_T )
409  {
410  if( m_boardGraphics->GetValue() )
411  visitItem( commit, boardItem );
412  }
413  }
414 
415  commit.Push( "Edit text and graphics properties" );
416  m_parent->GetCanvas()->Refresh();
417 
418  return true;
419 }
420 
421 
423 {
424  PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
425  DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS dlg( editFrame );
426 
427  dlg.ShowModal();
428  return 0;
429 }
430 
431 
#define SET_INT_VALUE(aRow, aCol, aValue)
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
TEXTE_PCB class definition.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void visitItem(const SCH_SHEET_PATH &aSheetPath, SCH_ITEM *aItem)
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
const LIB_ID & GetFPID() const
Definition: class_module.h:215
bool IsIndeterminate() const
Function IsIndeterminate Returns true if the control holds the indeterminate value (for instance,...
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
int GetTextThickness(PCB_LAYER_ID aLayer) const
Function GetTextThickness Returns the default text thickness from the layer class for the given layer...
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
const wxString GetReference() const
Function GetReference.
Definition: class_module.h:433
bool GetTextUpright(PCB_LAYER_ID aLayer) const
bool GetTextItalic(PCB_LAYER_ID aLayer) const
int GetLineThickness(PCB_LAYER_ID aLayer) const
Function GetLineThickness Returns the default graphic segment thickness from the layer class for the ...
wxSize m_TextSize[LAYER_CLASS_COUNT]
LAYER_NUM GetLayerSelection() const
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:467
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_EVENT.
Definition: tool_event.h:171
bool m_TextItalic[LAYER_CLASS_COUNT]
int SetLayerSelection(LAYER_NUM layer)
#define TEXTS_MAX_SIZE
Maximum text size in internal units (10 inches)
Definition: pcbnew.h:39
bool SetLayersHotkeys(bool value)
int m_LineThickness[LAYER_CLASS_COUNT]
UTF8 Format() const
Definition: lib_id.cpp:237
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:38
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
void SetUndefinedLayerName(const wxString &aName)
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED, bool aUseMils=false)
Function Validate Validates the control against the given range, informing the user of any errors fou...
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
#define INDETERMINATE_ACTION
#define SET_BOOL_VALUE(aRow, aCol, aValue)
PCB_EDIT_FRAME is the main frame for Pcbnew.
void processItem(const SCH_SHEET_PATH &aSheetPath, SCH_ITEM *aItem)
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
EDGE_MODULE class definition.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
BOARD_ITEM_CONTAINER * GetParent() const
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:849
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Function GetTextSize Returns the default text size from the layer class for the given layer.
bool m_TextUpright[LAYER_CLASS_COUNT]
void Enable(bool aEnable)
Function Enable Enables/diasables the label, widget and units label.
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.