KiCad PCB EDA Suite
dialog_global_modules_fields_edition.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, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 1992-2012 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 
30 #include <fctsys.h>
31 #include <common.h>
32 #include <class_drawpanel.h>
33 #include <wxBasePcbFrame.h>
34 #include <base_units.h>
35 #include <kicad_string.h>
36 #include <macros.h>
37 #include <board_commit.h>
38 
39 #include <pcbnew.h>
40 #include <wxPcbStruct.h>
41 
42 #include <class_board.h>
43 #include <class_module.h>
44 #include <class_text_mod.h>
46 
47 
48 // The dialog to set options for global fields edition:
49 // optionas are:
50 // - edited fields (ref, value, others
51 // - the footprint filter, for selective edition
53 {
56  // Static variable to remember options, withing a session:
57  static bool m_refSelection;
58  static bool m_valueSelection;
59  static bool m_othersSelection;
60  static wxString m_filterString;
61 
62 
63 public:
66  {
67  m_parent = parent;
68  initDialog();
69  }
70 
71 private:
72  void initDialog();
73 
74  bool TransferDataFromWindow() override;
75 };
76 
81 
83 {
84  m_sdbSizerButtonsOK->SetDefault();
85 
87 
88  m_ReferenceOpt->SetValue(m_refSelection),
89  m_ValueOpt->SetValue(m_valueSelection),
91  m_ModuleFilter->SetValue(m_filterString);
95  m_SizeX_Value->SetValue(
97  m_SizeY_Value->SetValue(
99  m_ThicknessValue->SetValue(
101 
102  Layout();
103  GetSizer()->SetSizeHints( this );
104  Centre();
105 }
106 
107 
109 {
110  m_refSelection = m_ReferenceOpt->GetValue();
111  m_valueSelection = m_ValueOpt->GetValue();
112  m_othersSelection = m_OtherFields->GetValue();
113  m_filterString = m_ModuleFilter->GetValue();
114 
118 
119  // clip m_ModuleTextWidth to the 1/4 of min size, to keep it always readable
120  int max_thickness = std::min( m_brdSettings->m_ModuleTextSize.x,
122  if( m_brdSettings->m_ModuleTextWidth > max_thickness )
123  m_brdSettings->m_ModuleTextWidth = max_thickness;
124 
127  return true;
128 }
129 
130 
131 void PCB_EDIT_FRAME::OnResetModuleTextSizes( wxCommandEvent& event )
132 {
134  dlg.ShowModal();
135 }
136 
137 void PCB_BASE_FRAME::ResetModuleTextSizes( const wxString & aFilter, bool aRef,
138  bool aValue, bool aOthers )
139 {
140  BOARD_COMMIT commit( this );
141 
142  int modTextWidth = GetDesignSettings().m_ModuleTextWidth;
143  const wxSize& modTextSize = GetDesignSettings().m_ModuleTextSize;
144  bool modified = false;
145 
146  // Change fields of footprints with fpid matching the filter
147  for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
148  {
149  if( !aFilter.IsEmpty() )
150  {
151  if( ! WildCompareString( aFilter, FROM_UTF8( module->GetFPID().Format().c_str() ),
152  false ) )
153  continue;
154  }
155 
156 
157  if( aRef )
158  {
159  TEXTE_MODULE* item = &module->Reference();
160 
163  {
164  commit.Modify( item );
165  item->SetThickness( modTextWidth );
166  item->SetTextSize( modTextSize );
167  modified = true;
168  }
169  }
170 
171  if( aValue )
172  {
173  TEXTE_MODULE* item = &module->Value();
174 
177  {
178  commit.Modify( item );
179  item->SetThickness( modTextWidth );
180  item->SetTextSize( modTextSize );
181  modified = true;
182  }
183  }
184 
185  if( aOthers )
186  {
187  // Go through all other module text fields
188  for( BOARD_ITEM* boardItem = module->GraphicalItemsList(); boardItem; boardItem = boardItem->Next() )
189  {
190  if( boardItem->Type() == PCB_MODULE_TEXT_T )
191  {
192  TEXTE_MODULE* item = static_cast<TEXTE_MODULE*>( boardItem );
193 
196  {
197  commit.Modify( item );
198  item->SetThickness( modTextWidth );
199  item->SetTextSize( modTextSize );
200  modified = true;
201  }
202  }
203  }
204  }
205  }
206 
207  if( modified )
208  {
209  commit.Push( "Reset module text size" );
210  GetCanvas()->Refresh();
211  }
212 }
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
Implementation of conversion functions that require both schematic and board internal units...
int m_ModuleTextWidth
Default footprint texts thickness.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:299
Class BOARD to handle a board.
wxString StringFromValue(EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:203
void ResetModuleTextSizes(const wxString &aFilter, bool aRef, bool aValue, bool aOthers)
Function ResetModuleTextSizes resets text size and width of all module text fields of given field typ...
BOARD * GetBoard() const
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
wxSize m_ModuleTextSize
Default footprint texts size.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true) override
Executes the changes.
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:154
This file contains miscellaneous commonly used macros and functions.
BOARD_ITEM * Next() const
Footprint text class description.
Class DIALOG_GLOBAL_MODULES_FIELDS_EDITION_BASE.
Classes used in Pcbnew, CvPcb and GerbView.
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:305
wxString GetAbbreviatedUnitsLabel(EDA_UNITS_T aUnit)
Definition: base_units.cpp:479
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
int ValueFromTextCtrl(const wxTextCtrl &aTextCtr)
Convert the number Value in a string according to the internal units and the selected unit (g_UserUni...
Definition: base_units.cpp:384
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:105
The common library.
Module description (excepted pads)
const wxSize & GetTextSize() const
Definition: eda_text.h:215
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:148
void OnResetModuleTextSizes(wxCommandEvent &event)
Function OnResetModuleTextSizes resets text size and width of all module text fields of given field t...
#define min(a, b)
Definition: auxiliary.h:85
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.