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 {
59 };
60 
61 
62 static bool g_modifyReferences;
63 static bool g_modifyValues;
64 static bool g_modifyOtherFields;
66 static bool g_modifyBoardText;
68 static bool g_filterByLayer;
70 static bool g_filterByReference;
71 static wxString g_referenceFilter;
72 static bool g_filterByFootprint;
73 static wxString g_footprintFilter;
74 
75 
77 {
80 
85 
86 public:
89 
90 protected:
91  void OnUpdateUI( wxUpdateUIEvent& event ) override;
92  void OnLayerFilterSelect( wxCommandEvent& event ) override
93  {
94  m_layerFilterOpt->SetValue( true );
95  }
96  void OnReferenceFilterText( wxCommandEvent& event ) override
97  {
98  m_referenceFilterOpt->SetValue( true );
99  }
100  void OnFootprintFilterText( wxCommandEvent& event ) override
101  {
102  m_footprintFilterOpt->SetValue( true );
103  }
104 
105  bool TransferDataToWindow() override;
106  bool TransferDataFromWindow() override;
107 
108  void visitItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem );
109  void processItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem );
110 };
111 
112 
115  m_lineWidth( parent, m_lineWidthLabel, m_LineWidthCtrl, m_lineWidthUnits, true ),
116  m_textWidth( parent, m_SizeXlabel, m_SizeXCtrl, m_SizeXunit, true ),
117  m_textHeight( parent, m_SizeYlabel, m_SizeYCtrl, m_SizeYunit, true ),
118  m_thickness( parent, m_ThicknessLabel, m_ThicknessCtrl, m_ThicknessUnit, true )
119 {
120  m_parent = parent;
122 
126 
128  m_LayerCtrl->SetLayersHotkeys( false );
129  m_LayerCtrl->Resync();
130 
131  m_grid->SetCellHighlightPenWidth( 0 );
132  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
133  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
134  m_grid->SetDefaultCellFont( infoFont );
135 
136  m_sdbSizerButtonsOK->SetDefault();
137 
139 }
140 
141 
143 {
144  g_modifyReferences = m_references->GetValue();
145  g_modifyValues = m_values->GetValue();
146  g_modifyOtherFields = m_otherFields->GetValue();
148  g_modifyBoardText = m_boardText->GetValue();
150 
151  g_filterByLayer = m_layerFilterOpt->GetValue();
154  g_referenceFilter = m_referenceFilter->GetValue();
156  g_footprintFilter = m_footprintFilter->GetValue();
157 }
158 
159 
161 {
162  m_references->SetValue( g_modifyReferences );
163  m_values->SetValue( g_modifyValues );
164  m_otherFields->SetValue( g_modifyOtherFields );
166  m_boardText->SetValue( g_modifyBoardText );
168 
169  if( m_layerFilter->SetLayerSelection( g_layerFilter ) != wxNOT_FOUND )
170  m_layerFilterOpt->SetValue( g_filterByLayer );
171 
172  // SetValue() generates events, ChangeValue() does not
173  m_referenceFilter->ChangeValue( g_referenceFilter );
175  m_footprintFilter->ChangeValue( g_footprintFilter );
177 
182  m_Italic->Set3StateValue( wxCHK_UNDETERMINED );
183  m_keepUpright->Set3StateValue( wxCHK_UNDETERMINED );
184  m_Visible->Set3StateValue( wxCHK_UNDETERMINED );
186 
187 #define SET_INT_VALUE( aRow, aCol, aValue ) \
188  m_grid->SetCellValue( aRow, aCol, StringFromValue( GetUserUnits(), aValue, true, true ) )
189 
190 #define SET_BOOL_VALUE( aRow, aCol, aValue ) \
191  attr = new wxGridCellAttr; \
192  attr->SetRenderer( new wxGridCellBoolRenderer() ); \
193  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM ); \
194  attr->SetReadOnly(); \
195  m_grid->SetAttr( aRow, aCol, attr ); \
196  m_grid->SetCellValue( aRow, aCol, ( aValue ) ? "1" : "" )
197 
199  wxGridCellAttr* attr;
200 
201  m_grid->SetCellValue( ROW_SILK, COL_CLASS_NAME, _( "Silk Layers" ) );
202  m_grid->SetCellValue( ROW_COPPER, COL_CLASS_NAME, _( "Copper Layers" ) );
203  m_grid->SetCellValue( ROW_EDGES, COL_CLASS_NAME, _( "Edge Cuts" ) );
204  m_grid->SetCellValue( ROW_COURTYARD, COL_CLASS_NAME, _( "Courtyards" ) );
205  m_grid->SetCellValue( ROW_OTHERS, COL_CLASS_NAME, _( "Other Layers" ) );
206 
207  m_grid->SetCellValue( ROW_HEADER, COL_LINE_THICKNESS, _( "Line Thickness" ) );
213 
214  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_WIDTH, _( "Text Width" ) );
218 
219  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_HEIGHT, _( "Text Height" ) );
223 
224  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_THICKNESS, _( "Text Thickness" ) );
228 
229  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_ITALIC, _( "Italic" ) );
233 
234  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_UPRIGHT, _( "Upright" ) );
238 
239  return true;
240 
241 #undef SET_INT_VALUE
242 #undef SET_BOOL_VALUE
243 }
244 
245 
247 {
252  m_Italic->Enable( m_setToSpecifiedValues->GetValue() );
253  m_Visible->Enable( m_setToSpecifiedValues->GetValue() );
254  m_LayerLabel->Enable( m_setToSpecifiedValues->GetValue() );
255  m_LayerCtrl->Enable( m_setToSpecifiedValues->GetValue() );
256  m_keepUpright->Enable( m_setToSpecifiedValues->GetValue() );
257 }
258 
259 
261 {
262  aCommit.Modify( aItem );
263 
264  auto textItem = dynamic_cast<EDA_TEXT*>( aItem );
265  auto drawItem = dynamic_cast<DRAWSEGMENT*>( aItem );
266  auto moduleTextItem = dyn_cast<TEXTE_MODULE*>( aItem );
267 
268  if( m_setToSpecifiedValues->GetValue() )
269  {
272 
273  if( !m_textWidth.IsIndeterminate() && textItem )
274  textItem->SetTextSize( wxSize( m_textWidth.GetValue(), textItem->GetTextSize().y ) );
275 
276  if( !m_textHeight.IsIndeterminate() && textItem )
277  textItem->SetTextSize( wxSize( textItem->GetTextSize().x, m_textHeight.GetValue() ) );
278 
279  if( !m_thickness.IsIndeterminate() && textItem )
280  textItem->SetThickness( m_thickness.GetValue() );
281 
282  if( m_Italic->Get3StateValue() != wxCHK_UNDETERMINED && textItem )
283  textItem->SetItalic( m_Italic->GetValue() );
284 
285  if( m_Visible->Get3StateValue() != wxCHK_UNDETERMINED && textItem )
286  textItem->SetVisible( m_Visible->GetValue() );
287 
288  if( m_keepUpright->Get3StateValue() != wxCHK_UNDETERMINED && moduleTextItem )
289  moduleTextItem->SetKeepUpright( m_keepUpright->GetValue() );
290 
291  if( !m_lineWidth.IsIndeterminate() && drawItem )
292  drawItem->SetWidth( m_lineWidth.GetValue() );
293  }
294  else
295  {
296  PCB_LAYER_ID layer = aItem->GetLayer();
297 
298  if( textItem )
299  {
300  textItem->SetTextSize( m_brdSettings->GetTextSize( layer ) );
301  textItem->SetThickness( m_brdSettings->GetTextThickness( layer ) );
302  textItem->SetItalic( m_brdSettings->GetTextItalic( layer ) );
303  }
304 
305  if( moduleTextItem )
306  moduleTextItem->SetKeepUpright( m_brdSettings->GetTextUpright( layer ) );
307 
308  if( drawItem )
309  drawItem->SetWidth( m_brdSettings->GetLineThickness( layer ) );
310  }
311 }
312 
313 
315 {
317  {
318  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
319  return;
320  }
321 
322  if( m_referenceFilterOpt->GetValue() && !m_referenceFilter->GetValue().IsEmpty() )
323  {
324  MODULE* module = dynamic_cast<MODULE*>( aItem->GetParent() );
325 
326  if( module )
327  {
328  if( !WildCompareString( m_referenceFilter->GetValue(), module->GetReference(), false ) )
329  return;
330  }
331  }
332 
333  if( m_footprintFilterOpt->GetValue() && !m_footprintFilter->GetValue().IsEmpty() )
334  {
335  MODULE* module = dynamic_cast<MODULE*>( aItem->GetParent() );
336 
337  if( module )
338  {
339  if( !WildCompareString( m_footprintFilter->GetValue(), module->GetFPID().Format(), false ) )
340  return;
341  }
342  }
343 
344  processItem( aCommit, aItem );
345 }
346 
347 
349 {
352  {
353  return false;
354  }
355 
356  BOARD_COMMIT commit( m_parent );
357 
358  // Go through the modules
359  for( MODULE* module : m_parent->GetBoard()->Modules() )
360  {
361  if( m_references->GetValue() )
362  visitItem( commit, &module->Reference() );
363 
364  if( m_values->GetValue() )
365  visitItem( commit, &module->Value() );
366 
367  // Go through all other module items
368  for( BOARD_ITEM* boardItem : module->GraphicalItems() )
369  {
370  if( boardItem->Type() == PCB_MODULE_TEXT_T )
371  {
372  const wxString text = dynamic_cast<EDA_TEXT*>( boardItem )->GetText();
373 
374  if( m_references->GetValue() && text == wxT( "%R" ) )
375  visitItem( commit, boardItem );
376  else if( m_values->GetValue() && text == wxT( "%V" ) )
377  visitItem( commit, boardItem );
378  else if( m_otherFields->GetValue() )
379  visitItem( commit, boardItem );
380  }
381  else if( boardItem->Type() == PCB_MODULE_EDGE_T )
382  {
383  if( m_footprintGraphics->GetValue() )
384  visitItem( commit, boardItem );
385  }
386  }
387  }
388 
389  // Go through the PCB text & graphic items
390  for( BOARD_ITEM* boardItem : m_parent->GetBoard()->Drawings() )
391  {
392  if( boardItem->Type() == PCB_TEXT_T )
393  {
394  if( m_boardText->GetValue() )
395  visitItem( commit, boardItem );
396  }
397  else if( boardItem->Type() == PCB_LINE_T )
398  {
399  if( m_boardGraphics->GetValue() )
400  visitItem( commit, boardItem );
401  }
402  }
403 
404  commit.Push( "Edit text and graphics properties" );
405  m_parent->GetCanvas()->Refresh();
406 
407  return true;
408 }
409 
410 
412 {
413  PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
414  DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS dlg( editFrame );
415 
416  dlg.ShowModal();
417  return 0;
418 }
419 
420 
#define SET_INT_VALUE(aRow, aCol, aValue)
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame.
TEXTE_PCB class definition.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual bool Validate(int aMin, int aMax, bool setFocusOnError=true)
Function Validate Validates the control against the given range, informing the user of any errors fou...
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
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
const LIB_ID & GetFPID() const
Definition: class_module.h:197
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:407
bool GetTextUpright(PCB_LAYER_ID aLayer) const
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
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]
MODULES & Modules()
Definition: class_board.h:236
#define INDETERMINATE
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:421
Class TOOL_EVENT.
Definition: tool_event.h:168
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)
#define _(s)
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.
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
#define SET_BOOL_VALUE(aRow, aCol, aValue)
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
Module description (excepted pads)
BOARD * GetBoard() const
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.
DRAWINGS & Drawings()
Definition: class_board.h:245
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:813
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.
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.