KiCad PCB EDA Suite
eeschema/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) 2019 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <fctsys.h>
25 #include <kicad_string.h>
26 #include <widgets/unit_binder.h>
27 #include <tool/tool_manager.h>
29 #include <tools/sch_edit_tool.h>
30 #include <sch_edit_frame.h>
31 #include <sch_component.h>
32 #include <sch_line.h>
33 #include <sch_connection.h>
34 #include <sch_sheet.h>
35 #include <connection_graph.h>
37 #include <advanced_config.h>
38 
39 static bool g_modifyReferences;
40 static bool g_modifyValues;
41 static bool g_modifyOtherFields;
42 static bool g_modifyWires;
43 static bool g_modifyBusses;
45 static bool g_modifyHierLabels;
46 static bool g_modifySheetTitles;
47 static bool g_modifySheetPins;
49 
50 static bool g_filterByFieldname;
51 static wxString g_fieldnameFilter;
52 static bool g_filterByReference;
53 static wxString g_referenceFilter;
54 static bool g_filterBySymbol;
55 static wxString g_symbolFilter;
56 static bool g_filterByNet;
57 static wxString g_netFilter;
58 
59 
61 {
63 
66 
67 public:
70 
71 protected:
72  void OnUpdateUI( wxUpdateUIEvent& event ) override;
73  void OnReferenceFilterText( wxCommandEvent& event ) override
74  {
75  m_referenceFilterOpt->SetValue( true );
76  }
77  void OnSymbolFilterText( wxCommandEvent& event ) override
78  {
79  m_symbolFilterOpt->SetValue( true );
80  }
81 
82  bool TransferDataToWindow() override;
83  bool TransferDataFromWindow() override;
84 
85  void visitItem( const SCH_SHEET_PATH& aSheetPath, SCH_ITEM* aItem );
86  void processItem( const SCH_SHEET_PATH& aSheetPath, SCH_ITEM* aItem );
87 };
88 
89 
92  m_textSize( parent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true ),
93  m_lineWidth( parent, m_lineWidthLabel, m_LineWidthCtrl, m_lineWidthUnits, true )
94 {
95  m_parent = parent;
96 
97  // TODO(JE) remove once real-time connectivity is a given
98  if( !ADVANCED_CFG::GetCfg().m_realTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
99  m_parent->RecalculateConnections();
100 
101  m_sdbSizerButtonsOK->SetDefault();
102 
104 }
105 
106 
108 {
109  g_modifyReferences = m_references->GetValue();
110  g_modifyValues = m_values->GetValue();
111  g_modifyOtherFields = m_otherFields->GetValue();
112  g_modifyWires = m_wires->GetValue();
113  g_modifyBusses = m_busses->GetValue();
114  g_modifyGlobalLabels = m_globalLabels->GetValue();
115  g_modifyHierLabels = m_hierLabels->GetValue();
116  g_modifySheetTitles = m_sheetTitles->GetValue();
117  g_modifySheetPins = m_sheetPins->GetValue();
119 
121  g_fieldnameFilter = m_fieldnameFilter->GetValue();
123  g_referenceFilter = m_referenceFilter->GetValue();
124  g_filterBySymbol = m_symbolFilterOpt->GetValue();
125  g_symbolFilter = m_symbolFilter->GetValue();
126  g_filterByNet = m_netFilterOpt->GetValue();
127  g_netFilter = m_netFilter->GetValue();
128 }
129 
130 
132 {
134  SELECTION& selection = selectionTool->GetSelection();
135 
136  m_references->SetValue( g_modifyReferences );
137  m_values->SetValue( g_modifyValues );
138  m_otherFields->SetValue( g_modifyOtherFields );
139  m_wires->SetValue( g_modifyWires );
140  m_busses->SetValue( g_modifyBusses );
142  m_hierLabels->SetValue( g_modifyHierLabels );
143  m_sheetTitles->SetValue( g_modifySheetTitles );
144  m_sheetPins->SetValue( g_modifySheetPins );
146 
147  // SetValue() generates events, ChangeValue() does not
148  m_fieldnameFilter->ChangeValue( g_fieldnameFilter );
150  m_referenceFilter->ChangeValue( g_referenceFilter );
152  m_symbolFilter->ChangeValue( g_symbolFilter );
153  m_symbolFilterOpt->SetValue( g_filterBySymbol );
154 
155  if( g_filterByNet && !g_netFilter.IsEmpty() )
156  {
157  m_netFilter->SetValue( g_netFilter );
158  m_netFilterOpt->SetValue( true );
159  }
160  else if( !m_parent->GetSelectedNetName().IsEmpty() )
161  {
162  m_netFilter->SetValue( m_parent->GetSelectedNetName() );
163  }
164  else if( selection.GetSize() )
165  {
166  SCH_ITEM* sch_item = (SCH_ITEM*) selection.Front();
167  SCH_CONNECTION* connection = sch_item->Connection( *g_CurrentSheet );
168 
169  if( connection )
170  m_netFilter->SetValue( connection->Name() );
171  }
172 
173  m_netFilterOpt->SetValue( g_filterByNet );
174 
176  m_orientation->SetStringSelection( INDETERMINATE );
177  m_hAlign->SetStringSelection( INDETERMINATE );
178  m_vAlign->SetStringSelection( INDETERMINATE );
179  m_Italic->Set3StateValue( wxCHK_UNDETERMINED );
180  m_Bold->Set3StateValue( wxCHK_UNDETERMINED );
181  m_Visible->Set3StateValue( wxCHK_UNDETERMINED );
183  m_lineStyle->SetStringSelection( INDETERMINATE );
184  m_setColor->SetValue( false );
185 
186  return true;
187 }
188 
189 
191 {
192 }
193 
194 
196  SCH_ITEM* aItem )
197 {
198  auto eda_text = dynamic_cast<EDA_TEXT*>( aItem );
199  auto sch_text = dynamic_cast<SCH_TEXT*>( aItem );
200  auto lineItem = dynamic_cast<SCH_LINE*>( aItem );
201 
202  if( eda_text )
203  {
204  if( !m_textSize.IsIndeterminate() )
205  eda_text->SetTextSize( wxSize( m_textSize.GetValue(), m_textSize.GetValue() ) );
206 
207  if( m_hAlign->GetStringSelection() != INDETERMINATE )
208  eda_text->SetHorizJustify( EDA_TEXT::MapHorizJustify( m_hAlign->GetSelection() - 1 ) );
209 
210  if( m_hAlign->GetStringSelection() != INDETERMINATE )
211  eda_text->SetVertJustify( EDA_TEXT::MapVertJustify( m_vAlign->GetSelection() - 1 ) );
212 
213  if( m_Visible->Get3StateValue() != wxCHK_UNDETERMINED )
214  eda_text->SetVisible( m_Visible->GetValue() );
215 
216  if( m_Italic->Get3StateValue() != wxCHK_UNDETERMINED )
217  eda_text->SetItalic( m_Visible->GetValue() );
218 
219  if( m_Bold->Get3StateValue() != wxCHK_UNDETERMINED )
220  eda_text->SetBold( m_Visible->GetValue() );
221  }
222 
223  // No else! Labels are both.
224  if( sch_text )
225  {
226  if( m_orientation->GetStringSelection() != INDETERMINATE )
227  {
228  int orient = m_orientation->GetSelection();
229  sch_text->SetLabelSpinStyle( EDA_TEXT::MapOrientation( sch_text->Type(), orient ) );
230  }
231  }
232 
233  if( lineItem )
234  {
236  lineItem->SetLineWidth( m_lineWidth.GetValue() );
237 
238  if( lineItem->GetLayer() == LAYER_NOTES )
239  {
240  if( m_lineStyle->GetStringSelection() != INDETERMINATE )
241  lineItem->SetLineStyle( m_lineStyle->GetSelection() );
242 
243  if( m_setColor->GetValue() )
244  lineItem->SetLineColor( m_color->GetColour() );
245  }
246  }
247 
248  m_parent->OnModify();
249 }
250 
252  SCH_ITEM* aItem )
253 {
254  if( m_netFilterOpt->GetValue() && !m_netFilter->GetValue().IsEmpty() )
255  {
256  SCH_CONNECTION* connection = aItem->Connection( aSheetPath );
257 
258  if( !connection )
259  return;
260 
261  if( !WildCompareString( m_netFilter->GetValue(), connection->Name(), false ) )
262  return;
263  }
264 
265  if( m_referenceFilterOpt->GetValue() && !m_referenceFilter->GetValue().IsEmpty() )
266  {
267  if( aItem->Type() == SCH_COMPONENT_T )
268  {
269  wxString ref = static_cast<SCH_COMPONENT*>( aItem )->GetRef( &aSheetPath );
270 
271  if( !WildCompareString( m_referenceFilter->GetValue(), ref, false ) )
272  return;
273  }
274  }
275 
276  if( m_symbolFilterOpt->GetValue() && !m_symbolFilter->GetValue().IsEmpty() )
277  {
278  if( aItem->Type() == SCH_COMPONENT_T )
279  {
280  wxString id = static_cast<SCH_COMPONENT*>( aItem )->GetLibId().Format();
281 
282  if( !WildCompareString( m_symbolFilter->GetValue(), id, false ) )
283  return;
284  }
285  }
286 
287  static KICAD_T wireTypes[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LABEL_LOCATE_WIRE_T, EOT };
288  static KICAD_T busTypes[] = { SCH_LINE_LOCATE_BUS_T, SCH_LABEL_LOCATE_BUS_T, EOT };
289  static KICAD_T schTextAndGraphics[] = { SCH_TEXT_T, SCH_LINE_LOCATE_GRAPHIC_LINE_T, EOT };
290 
291  if( aItem->Type() == SCH_COMPONENT_T )
292  {
293  SCH_COMPONENT* component = (SCH_COMPONENT*) aItem;
294 
295  if( m_references->GetValue() )
296  processItem( aSheetPath, component->GetField( REFERENCE ) );
297 
298  if( m_values->GetValue() )
299  processItem( aSheetPath, component->GetField( VALUE ) );
300 
301  if( m_otherFields->GetValue() )
302  {
303  for( int i = 2; i < component->GetFieldCount(); ++i )
304  {
305  SCH_FIELD* field = component->GetField( i );
306  const wxString& fieldName = field->GetName();
307 
308  if( !m_fieldnameFilterOpt->GetValue() || m_fieldnameFilter->GetValue().IsEmpty()
309  || WildCompareString( m_fieldnameFilter->GetValue(), fieldName, false ) )
310  {
311  processItem( aSheetPath, field );
312  }
313  }
314  }
315  }
316  else if( m_wires->GetValue() && aItem->IsType( wireTypes ) )
317  processItem( aSheetPath, aItem );
318  else if( m_busses->GetValue() && aItem->IsType( busTypes ) )
319  processItem( aSheetPath, aItem );
320  else if( m_globalLabels->GetValue() && aItem->Type() == SCH_GLOBAL_LABEL_T )
321  processItem( aSheetPath, aItem );
322  else if( m_hierLabels->GetValue() && aItem->Type() == SCH_HIER_LABEL_T )
323  processItem( aSheetPath, aItem );
324  else if( m_sheetTitles->GetValue() && aItem->Type() == SCH_SHEET_T )
325  {
326  if( !m_textSize.IsIndeterminate() )
327  static_cast<SCH_SHEET*>( aItem )->SetSheetNameSize( m_textSize.GetValue() );
328  }
329  else if( m_sheetPins->GetValue() && aItem->Type() == SCH_SHEET_PIN_T )
330  processItem( aSheetPath, aItem );
331  else if( m_schTextAndGraphics->GetValue() && aItem->IsType( schTextAndGraphics ) )
332  processItem( aSheetPath, aItem );
333 }
334 
335 
337 {
338  if( !m_textSize.Validate( 1, 10000 ) ) // 1 mill .. 10 inches
339  return false;
340 
341  SCH_SHEET_LIST aSheets( g_RootSheet );
342 
343  // Go through sheets
344  for( const SCH_SHEET_PATH& sheetPath : aSheets )
345  {
346  SCH_SCREEN* screen = sheetPath.LastScreen();
347 
348  if( screen )
349  {
350  for( SCH_ITEM* item = screen->GetDrawItems(); item; item = item->Next() )
351  visitItem( sheetPath, item );
352  }
353  }
354 
355  m_parent->HardRedraw();
356 
357  return true;
358 }
359 
360 
362 {
364  dlg.ShowModal();
365  return 0;
366 }
367 
368 
Class SCH_SHEET_LIST.
Class SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
SCH_ITEM * Next() const
Definition: sch_item.h:153
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
virtual bool IsType(const KICAD_T aScanTypes[])
Function IsType Checks whether the item is one of the listed types.
Definition: base_struct.h:294
Schematic editor (Eeschema) main window.
bool IsIndeterminate() const
Function IsIndeterminate Returns true if the control holds the indeterminate value (for instance,...
Field Reference of part, i.e. "IC21".
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
EE_SELECTION & GetSelection()
Function GetSelection()
#define VALUE
wxString Name(bool aIgnoreSheet=false) const
static EDA_TEXT_HJUSTIFY_T MapHorizJustify(int aHorizJustify)
Definition: eda_text.cpp:73
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:47
SCH_SHEET_PATH * g_CurrentSheet
With the new connectivity algorithm, many more places than before want to know what the current sheet...
#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:433
Class TOOL_EVENT.
Definition: tool_event.h:168
Class SCH_SHEET_PATH.
virtual bool Validate(long long int aMin, long long int aMax, bool setFocusOnError=true)
Function Validate Validates the control against the given range, informing the user of any errors fou...
int GetFieldCount() const
Return the number of fields in this symbol.
static EDA_TEXT_VJUSTIFY_T MapVertJustify(int aVertJustify)
Definition: eda_text.cpp:87
virtual void HardRedraw()
Rebuild the GAL and redraws the screen.
SCH_CONNECTION * Connection(const SCH_SHEET_PATH &aPath) const
Retrieves the connection associated with this object in the given sheet.
Definition: sch_item.cpp:128
static bool m_allowRealTime
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
static int MapOrientation(KICAD_T labelType, int aOrientation)
Definition: eda_text.cpp:47
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:370
size_t i
Definition: json11.cpp:597
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:152