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  // event handlers
75  void OnOKClick( wxCommandEvent& event ) override;
76  void OnCancelClick( wxCommandEvent& event ) override
77  {
78  EndModal( wxID_CANCEL );
79  }
80 };
81 
86 
88 {
89  m_sdbSizerButtonsOK->SetDefault();
90 
92 
93  m_ReferenceOpt->SetValue(m_refSelection),
94  m_ValueOpt->SetValue(m_valueSelection),
96  m_ModuleFilter->SetValue(m_filterString);
100  m_SizeX_Value->SetValue(
102  m_SizeY_Value->SetValue(
104  m_ThicknessValue->SetValue(
106 
107  Layout();
108  GetSizer()->SetSizeHints( this );
109  Centre();
110 }
111 
112 
114 {
115  m_refSelection = m_ReferenceOpt->GetValue();
116  m_valueSelection = m_ValueOpt->GetValue();
117  m_othersSelection = m_OtherFields->GetValue();
118  m_filterString = m_ModuleFilter->GetValue();
119 
123 
124  // clip m_ModuleTextWidth to the 1/4 of min size, to keep it always readable
125  int minsize = std::min( m_brdSettings->m_ModuleTextSize.x,
127  if( m_brdSettings->m_ModuleTextWidth > minsize )
128  m_brdSettings->m_ModuleTextWidth = minsize;
129 
132  EndModal( wxID_OK );
133 }
134 
135 
136 void PCB_EDIT_FRAME::OnResetModuleTextSizes( wxCommandEvent& event )
137 {
139  dlg.ShowModal();
140 }
141 
142 void PCB_BASE_FRAME::ResetModuleTextSizes( const wxString & aFilter, bool aRef,
143  bool aValue, bool aOthers )
144 {
145  BOARD_COMMIT commit( this );
146 
147  int modTextWidth = GetDesignSettings().m_ModuleTextWidth;
148  const wxSize& modTextSize = GetDesignSettings().m_ModuleTextSize;
149 
150  // Prepare undo list
151  for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
152  {
153  if( ! aFilter.IsEmpty() )
154  {
155  if( ! WildCompareString( aFilter, FROM_UTF8( module->GetFPID().Format().c_str() ),
156  false ) )
157  continue;
158  }
159 
160 
161  if( aRef )
162  {
163  TEXTE_MODULE* item = &module->Reference();
164 
167  {
168  commit.Modify( item );
169  item->SetThickness( modTextWidth );
170  item->SetTextSize( modTextSize );
171  }
172  }
173 
174  if( aValue )
175  {
176  TEXTE_MODULE* item = &module->Value();
177 
180  {
181  commit.Modify( item );
182  item->SetThickness( modTextWidth );
183  item->SetTextSize( modTextSize );
184  }
185  }
186 
187  if( aOthers )
188  {
189  // Go through all other module text fields
190  for( BOARD_ITEM* boardItem = module->GraphicalItems(); boardItem; boardItem = boardItem->Next() )
191  {
192  if( boardItem->Type() == PCB_MODULE_TEXT_T )
193  {
194  TEXTE_MODULE* item = static_cast<TEXTE_MODULE*>( boardItem );
195 
198  {
199  commit.Modify( item );
200  item->SetThickness( modTextWidth );
201  item->SetTextSize( modTextSize );
202  }
203  }
204  }
205  }
206  }
207 
208  commit.Push( wxT( "Reset module text size" ) );
209 }
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
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...
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.