KiCad PCB EDA Suite
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 <class_drawpanel.h>
27 #include <kicad_string.h>
28 #include <board_commit.h>
29 #include <pcb_edit_frame.h>
30 #include <pcb_layer_box_selector.h>
31 #include <class_board.h>
32 #include <class_module.h>
33 #include <class_edge_mod.h>
34 #include <class_pcb_text.h>
35 #include <widgets/unit_binder.h>
36 
38 
39 
40 // Columns of layer classes grid
41 enum
42 {
50 };
51 
52 enum
53 {
60 };
61 
62 
65 
66 
68 {
71 
76 
77 public:
80 
81 protected:
82  void OnUpdateUI( wxUpdateUIEvent& event ) override;
83  void OnLayerFilterSelect( wxCommandEvent& event ) override
84  {
85  m_layerFilterOpt->SetValue( true );
86  }
87  void OnReferenceFilterText( wxCommandEvent& event ) override
88  {
89  m_referenceFilterOpt->SetValue( true );
90  }
91  void OnFootprintFilterText( wxCommandEvent& event ) override
92  {
93  m_footprintFilterOpt->SetValue( true );
94  }
95 
96  bool TransferDataToWindow() override;
97  bool TransferDataFromWindow() override;
98 
99  void visitItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem );
100  void processItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem );
101 };
102 
103 
107  m_textWidth( parent, m_SizeXlabel, m_SizeXCtrl, m_SizeXunit, true ),
110 {
111  m_parent = parent;
113 
117 
119  m_LayerCtrl->SetLayersHotkeys( false );
120  m_LayerCtrl->Resync();
121 
122  m_grid->SetCellHighlightPenWidth( 0 );
123  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
124  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
125  m_grid->SetDefaultCellFont( infoFont );
126 
127  m_sdbSizerButtonsOK->SetDefault();
128 
130 }
131 
132 
134 {
137 }
138 
139 
141 {
142  // SetValue() generates events, ChangeValue() does not
145 
150  m_Italic->Set3StateValue( wxCHK_UNDETERMINED );
151  m_keepUpright->Set3StateValue( wxCHK_UNDETERMINED );
152  m_Visible->Set3StateValue( wxCHK_UNDETERMINED );
154 
155 #define SET_INT_VALUE( aRow, aCol, aValue ) \
156  m_grid->SetCellValue( aRow, aCol, StringFromValue( GetUserUnits(), aValue, true, true ) )
157 
158 #define SET_BOOL_VALUE( aRow, aCol, aValue ) \
159  attr = new wxGridCellAttr; \
160  attr->SetRenderer( new wxGridCellBoolRenderer() ); \
161  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM ); \
162  attr->SetReadOnly(); \
163  m_grid->SetAttr( aRow, aCol, attr ); \
164  m_grid->SetCellValue( aRow, aCol, ( aValue ) ? "1" : "" )
165 
167  wxGridCellAttr* attr;
168 
169  m_grid->SetCellValue( ROW_SILK, COL_CLASS_NAME, _( "Silk Layers" ) );
170  m_grid->SetCellValue( ROW_COPPER, COL_CLASS_NAME, _( "Copper Layers" ) );
171  m_grid->SetCellValue( ROW_EDGES, COL_CLASS_NAME, _( "Edge Cuts" ) );
172  m_grid->SetCellValue( ROW_COURTYARD, COL_CLASS_NAME, _( "Courtyards" ) );
173  m_grid->SetCellValue( ROW_OTHERS, COL_CLASS_NAME, _( "Other Layers" ) );
174 
175  m_grid->SetCellValue( ROW_HEADER, COL_LINE_THICKNESS, _( "Line Thickness" ) );
181 
182  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_WIDTH, _( "Text Width" ) );
186 
187  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_HEIGHT, _( "Text Height" ) );
191 
192  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_THICKNESS, _( "Text Thickness" ) );
196 
197  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_ITALIC, _( "Italic" ) );
201 
202  m_grid->SetCellValue( ROW_HEADER, COL_TEXT_UPRIGHT, _( "Upright" ) );
206 
207  return true;
208 
209 #undef SET_INT_VALUE
210 #undef SET_BOOL_VALUE
211 }
212 
213 
215 {
220  m_Italic->Enable( m_setToSpecifiedValues->GetValue() );
221  m_Visible->Enable( m_setToSpecifiedValues->GetValue() );
222  m_LayerLabel->Enable( m_setToSpecifiedValues->GetValue() );
223  m_LayerCtrl->Enable( m_setToSpecifiedValues->GetValue() );
224  m_keepUpright->Enable( m_setToSpecifiedValues->GetValue() );
225 }
226 
227 
229 {
230  aCommit.Modify( aItem );
231 
232  auto textItem = dynamic_cast<EDA_TEXT*>( aItem );
233  auto drawItem = dynamic_cast<DRAWSEGMENT*>( aItem );
234  auto moduleTextItem = dyn_cast<TEXTE_MODULE*>( aItem );
235 
236  if( m_setToSpecifiedValues->GetValue() )
237  {
240 
241  if( !m_textWidth.IsIndeterminate() && textItem )
242  textItem->SetTextSize( wxSize( m_textWidth.GetValue(), textItem->GetTextSize().y ) );
243 
244  if( !m_textHeight.IsIndeterminate() && textItem )
245  textItem->SetTextSize( wxSize( textItem->GetTextSize().x, m_textHeight.GetValue() ) );
246 
247  if( !m_thickness.IsIndeterminate() && textItem )
248  textItem->SetThickness( m_thickness.GetValue() );
249 
250  if( m_Italic->Get3StateValue() != wxCHK_UNDETERMINED && textItem )
251  textItem->SetItalic( m_Italic->GetValue() );
252 
253  if( m_Visible->Get3StateValue() != wxCHK_UNDETERMINED && textItem )
254  textItem->SetVisible( m_Visible->GetValue() );
255 
256  if( m_keepUpright->Get3StateValue() != wxCHK_UNDETERMINED && moduleTextItem )
257  moduleTextItem->SetKeepUpright( m_keepUpright->GetValue() );
258 
259  if( !m_lineWidth.IsIndeterminate() && drawItem )
260  drawItem->SetWidth( m_lineWidth.GetValue() );
261  }
262  else
263  {
264  PCB_LAYER_ID layer = aItem->GetLayer();
265 
266  if( textItem )
267  {
268  textItem->SetTextSize( m_brdSettings->GetTextSize( layer ) );
269  textItem->SetThickness( m_brdSettings->GetTextThickness( layer ) );
270  textItem->SetItalic( m_brdSettings->GetTextItalic( layer ) );
271  }
272 
273  if( moduleTextItem )
274  moduleTextItem->SetKeepUpright( m_brdSettings->GetTextUpright( layer ) );
275 
276  if( drawItem )
277  drawItem->SetWidth( m_brdSettings->GetLineThickness( layer ) );
278  }
279 }
280 
281 
283 {
285  {
286  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
287  return;
288  }
289 
290  if( m_referenceFilterOpt->GetValue() && !m_referenceFilter->GetValue().IsEmpty() )
291  {
292  MODULE* module = dynamic_cast<MODULE*>( aItem->GetParent() );
293 
294  if( module )
295  {
296  if( !WildCompareString( m_referenceFilter->GetValue(), module->GetReference(), false ) )
297  return;
298  }
299  }
300 
301  if( m_footprintFilterOpt->GetValue() && !m_footprintFilter->GetValue().IsEmpty() )
302  {
303  MODULE* module = dynamic_cast<MODULE*>( aItem->GetParent() );
304 
305  if( module )
306  {
307  if( !WildCompareString( m_footprintFilter->GetValue(), module->GetFPID().Format(), false ) )
308  return;
309  }
310  }
311 
312  processItem( aCommit, aItem );
313 }
314 
315 
317 {
320  {
321  return false;
322  }
323 
324  BOARD_COMMIT commit( m_parent );
325 
326  // Go through the modules
327  for( MODULE* module : m_parent->GetBoard()->Modules() )
328  {
329  if( m_references->GetValue() )
330  visitItem( commit, &module->Reference() );
331 
332  if( m_values->GetValue() )
333  visitItem( commit, &module->Value() );
334 
335  // Go through all other module items
336  for( BOARD_ITEM* boardItem : module->GraphicalItems() )
337  {
338  if( boardItem->Type() == PCB_MODULE_TEXT_T )
339  {
340  const wxString& text = dynamic_cast<EDA_TEXT*>( boardItem )->GetText();
341 
342  if( m_references->GetValue() && text == wxT( "%R" ) )
343  visitItem( commit, boardItem );
344  else if( m_values->GetValue() && text == wxT( "%V" ) )
345  visitItem( commit, boardItem );
346  else if( m_otherFields->GetValue() )
347  visitItem( commit, boardItem );
348  }
349  else if( boardItem->Type() == PCB_MODULE_EDGE_T )
350  {
351  if( m_footprintGraphics->GetValue() )
352  visitItem( commit, boardItem );
353  }
354  }
355  }
356 
357  // Go through the PCB text & graphic items
358  for( BOARD_ITEM* boardItem : m_parent->GetBoard()->Drawings() )
359  {
360  if( boardItem->Type() == PCB_TEXT_T )
361  {
362  if( m_boardText->GetValue() )
363  visitItem( commit, boardItem );
364  }
365  else if( boardItem->Type() == PCB_LINE_T )
366  {
367  if( m_boardGraphics->GetValue() )
368  visitItem( commit, boardItem );
369  }
370  }
371 
372  commit.Push( "Edit text and graphics properties" );
373  m_parent->GetCanvas()->Refresh();
374 
375  return true;
376 }
377 
378 
379 void PCB_EDIT_FRAME::OnEditTextAndGraphics( wxCommandEvent& event )
380 {
382  dlg.ShowModal();
383 }
384 
385 
BOARD_ITEM_CONTAINER * GetParent() const
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
virtual EDA_DRAW_PANEL * GetCanvas() const
Definition: draw_frame.h:385
TEXTE_PCB class definition.
bool GetTextItalic(PCB_LAYER_ID aLayer) const
void OnFootprintFilterText(wxCommandEvent &event) override
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...
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
Class BOARD to handle a board.
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
void OnReferenceFilterText(wxCommandEvent &event) override
BOARD * GetBoard() const
int GetTextThickness(PCB_LAYER_ID aLayer) const
Function GetTextThickness Returns the default text thickness from the layer class for the given layer...
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Function GetTextSize Returns the default text size from the layer class for the given layer...
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
Casted dyn_cast(From aObject)
Function dyn_cast()
Definition: typeinfo.h:61
Class DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS_BASE.
#define SET_BOOL_VALUE(aRow, aCol, aValue)
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:127
const LIB_ID & GetFPID() const
Definition: class_module.h:192
wxSize m_TextSize[LAYER_CLASS_COUNT]
PCB_LAYER_ID
A quick note on layer IDs:
int m_TextThickness[LAYER_CLASS_COUNT]
DLIST_ITERATOR_WRAPPER< MODULE > Modules()
Definition: class_board.h:255
#define INDETERMINATE
bool WildCompareString(const wxString &pattern, const wxString &string_to_tst, bool case_sensitive)
Function WildCompareString compares a string against wild card (* and ?) pattern using the usual rule...
Definition: string.cpp:377
bool m_TextItalic[LAYER_CLASS_COUNT]
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:539
int SetLayerSelection(LAYER_NUM layer)
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
#define TEXTS_MAX_SIZE
Maximum text size in internal units (10 inches)
Definition: pcbnew.h:68
bool SetLayersHotkeys(bool value)
void OnEditTextAndGraphics(wxCommandEvent &event)
Function OnEditTextAndGraphics Dialog for editing properties of text and graphic items, selected by type, layer, and/or parent footprint.
int m_LineThickness[LAYER_CLASS_COUNT]
int GetLineThickness(PCB_LAYER_ID aLayer) const
Function GetLineThickness Returns the default graphic segment thickness from the layer class for the ...
#define TEXTS_MIN_SIZE
Minimum text size in internal units (1 mil)
Definition: pcbnew.h:67
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
void OnLayerFilterSelect(wxCommandEvent &event) override
bool GetTextUpright(PCB_LAYER_ID aLayer) const
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:462
void visitItem(BOARD_COMMIT &aCommit, BOARD_ITEM *aItem)
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
LAYER_NUM GetLayerSelection() const
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
bool IsIndeterminate() const
Function IsIndeterminate Returns true if the control holds the indeterminate value (for instance...
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
UTF8 Format() const
Definition: lib_id.cpp:237
void processItem(BOARD_COMMIT &aCommit, BOARD_ITEM *aItem)
Module description (excepted pads)
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
EDGE_MODULE class definition.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:813
static wxString g_textAndGraphicsFootprintFilter
bool m_TextUpright[LAYER_CLASS_COUNT]
void Enable(bool aEnable)
Function Enable Enables/diasables the label, widget and units label.
DLIST_ITERATOR_WRAPPER< BOARD_ITEM > Drawings()
Definition: class_board.h:256
static wxString g_textAndGraphicsReferenceFilter
#define SET_INT_VALUE(aRow, aCol, aValue)
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.