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-2021 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 <connection_graph.h>
26 #include <kicad_string.h>
27 #include <sch_symbol.h>
28 #include <sch_connection.h>
29 #include <sch_edit_frame.h>
30 #include <sch_line.h>
31 #include <sch_junction.h>
32 #include <sch_sheet.h>
33 #include <schematic.h>
34 #include <advanced_config.h>
35 #include <tool/tool_manager.h>
37 #include <tools/sch_edit_tool.h>
38 #include <widgets/unit_binder.h>
39 
40 static bool g_modifyReferences;
41 static bool g_modifyValues;
42 static bool g_modifyOtherFields;
43 static bool g_modifyWires;
44 static bool g_modifyBuses;
46 static bool g_modifyHierLabels;
47 static bool g_modifySheetTitles;
49 static bool g_modifySheetPins;
52 
53 static bool g_filterByFieldname;
54 static wxString g_fieldnameFilter;
55 static bool g_filterByReference;
56 static wxString g_referenceFilter;
57 static bool g_filterBySymbol;
58 static wxString g_symbolFilter;
59 static bool g_filterByType;
60 static bool g_typeFilterIsPower;
61 static bool g_filterByNet;
62 static wxString g_netFilter;
63 static bool g_filterSelected;
64 
65 
66 #define DEFAULT_STYLE _( "Default" )
67 
69 {
72 
75 
77 
78 public:
81 
82 protected:
83  void OnUpdateUI( wxUpdateUIEvent& event ) override;
84  void OnReferenceFilterText( wxCommandEvent& event ) override
85  {
86  m_referenceFilterOpt->SetValue( true );
87  }
88  void OnSymbolFilterText( wxCommandEvent& event ) override
89  {
90  m_symbolFilterOpt->SetValue( true );
91  }
92 
93  bool TransferDataToWindow() override;
94  bool TransferDataFromWindow() override;
95 
96  void visitItem( const SCH_SHEET_PATH& aSheetPath, SCH_ITEM* aItem );
97  void processItem( const SCH_SHEET_PATH& aSheetPath, SCH_ITEM* aItem );
98 };
99 
100 
103  m_textSize( parent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true ),
104  m_lineWidth( parent, m_lineWidthLabel, m_LineWidthCtrl, m_lineWidthUnits, true )
105 {
106  m_parent = parent;
107  m_hasChange = false;
108 
109  // TODO(JE) remove once real-time connectivity is a given
110  if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
112 
113  m_lineStyle->Append( DEFAULT_STYLE );
115 
116  m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
117  m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
118  m_bgColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
119  m_bgColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
120 
121  m_sdbSizerButtonsOK->SetDefault();
122 
124 }
125 
126 
128 {
129  g_modifyReferences = m_references->GetValue();
130  g_modifyValues = m_values->GetValue();
131  g_modifyOtherFields = m_otherFields->GetValue();
132  g_modifyWires = m_wires->GetValue();
133  g_modifyBuses = m_buses->GetValue();
134  g_modifyGlobalLabels = m_globalLabels->GetValue();
135  g_modifyHierLabels = m_hierLabels->GetValue();
136  g_modifySheetTitles = m_sheetTitles->GetValue();
138  g_modifySheetPins = m_sheetPins->GetValue();
139  g_modifySheetBorders = m_sheetBorders->GetValue();
141 
143  g_fieldnameFilter = m_fieldnameFilter->GetValue();
145  g_referenceFilter = m_referenceFilter->GetValue();
146  g_filterBySymbol = m_symbolFilterOpt->GetValue();
147  g_symbolFilter = m_symbolFilter->GetValue();
148  g_filterByType = m_typeFilterOpt->GetValue();
149  g_typeFilterIsPower = m_typeFilter->GetSelection() == 1;
150  g_filterByNet = m_netFilterOpt->GetValue();
151  g_netFilter = m_netFilter->GetValue();
153 }
154 
155 
157 {
159  m_selection = selectionTool->GetSelection();
160 
161  m_references->SetValue( g_modifyReferences );
162  m_values->SetValue( g_modifyValues );
163  m_otherFields->SetValue( g_modifyOtherFields );
164  m_wires->SetValue( g_modifyWires );
165  m_buses->SetValue( g_modifyBuses );
167  m_hierLabels->SetValue( g_modifyHierLabels );
168  m_sheetTitles->SetValue( g_modifySheetTitles );
170  m_sheetPins->SetValue( g_modifySheetPins );
173 
174  // SetValue() generates events, ChangeValue() does not
175  m_fieldnameFilter->ChangeValue( g_fieldnameFilter );
177  m_referenceFilter->ChangeValue( g_referenceFilter );
179  m_symbolFilter->ChangeValue( g_symbolFilter );
180  m_symbolFilterOpt->SetValue( g_filterBySymbol );
181  m_typeFilter->SetSelection( g_typeFilterIsPower ? 1 : 0 );
182  m_typeFilterOpt->SetValue( g_filterByType );
184 
185  if( g_filterByNet && !g_netFilter.IsEmpty() )
186  {
187  m_netFilter->SetValue( g_netFilter );
188  m_netFilterOpt->SetValue( true );
189  }
190  else if( m_parent->GetHighlightedConnection() )
191  {
193  }
194  else if( m_selection.GetSize() )
195  {
196  SCH_ITEM* sch_item = (SCH_ITEM*) m_selection.Front();
197  SCH_CONNECTION* connection = sch_item->Connection();
198 
199  if( connection )
200  m_netFilter->SetValue( connection->Name() );
201  }
202 
203  m_netFilterOpt->SetValue( g_filterByNet );
204 
206  m_orientation->SetStringSelection( INDETERMINATE_ACTION );
207  m_hAlign->SetStringSelection( INDETERMINATE_ACTION );
208  m_vAlign->SetStringSelection( INDETERMINATE_ACTION );
209  m_Italic->Set3StateValue( wxCHK_UNDETERMINED );
210  m_Bold->Set3StateValue( wxCHK_UNDETERMINED );
211  m_Visible->Set3StateValue( wxCHK_UNDETERMINED );
213  m_lineStyle->SetStringSelection( INDETERMINATE_ACTION );
214  m_setColor->SetValue( false );
215  m_setBgColor->SetValue( false );
216 
217  return true;
218 }
219 
220 
222 {
223 }
224 
225 
227  SCH_ITEM* aItem )
228 {
229  EDA_TEXT* eda_text = dynamic_cast<EDA_TEXT*>( aItem );
230  SCH_TEXT* sch_text = dynamic_cast<SCH_TEXT*>( aItem );
231  SCH_LINE* lineItem = dynamic_cast<SCH_LINE*>( aItem );
232 
234 
235  if( eda_text )
236  {
237  if( !m_textSize.IsIndeterminate() )
238  {
239  eda_text->SetTextSize( wxSize( m_textSize.GetValue(), m_textSize.GetValue() ) );
240  m_hasChange = true;
241  }
242 
243  if( m_hAlign->GetStringSelection() != INDETERMINATE_ACTION )
244  {
245  eda_text->SetHorizJustify( EDA_TEXT::MapHorizJustify( m_hAlign->GetSelection() - 1 ) );
246  m_hasChange = true;
247  }
248 
249  if( m_vAlign->GetStringSelection() != INDETERMINATE_ACTION )
250  {
251  eda_text->SetVertJustify( EDA_TEXT::MapVertJustify( m_vAlign->GetSelection() - 1 ) );
252  m_hasChange = true;
253  }
254 
255  if( m_Visible->Get3StateValue() != wxCHK_UNDETERMINED )
256  {
257  eda_text->SetVisible( m_Visible->GetValue() );
258  m_hasChange = true;
259  }
260 
261  if( m_Italic->Get3StateValue() != wxCHK_UNDETERMINED )
262  {
263  eda_text->SetItalic( m_Italic->GetValue() );
264  m_hasChange = true;
265  }
266 
267  if( m_Bold->Get3StateValue() != wxCHK_UNDETERMINED )
268  {
269  eda_text->SetBold( m_Bold->GetValue() );
270  m_hasChange = true;
271  }
272  }
273 
274  // No else! Labels are both.
275  if( sch_text )
276  {
277  if( m_orientation->GetStringSelection() != INDETERMINATE_ACTION )
278  {
279  sch_text->SetLabelSpinStyle( (LABEL_SPIN_STYLE::SPIN) m_orientation->GetSelection() );
280  m_hasChange = true;
281  }
282  }
283 
284  if( lineItem )
285  {
287  {
288  lineItem->SetLineWidth( m_lineWidth.GetValue() );
289  m_hasChange = true;
290  }
291 
292  if( m_lineStyle->GetStringSelection() != INDETERMINATE_ACTION )
293  {
294  if( m_lineStyle->GetStringSelection() == DEFAULT_STYLE )
296  else
297  lineItem->SetLineStyle( m_lineStyle->GetSelection() );
298 
299  m_hasChange = true;
300  }
301 
302  if( m_setColor->GetValue() )
303  {
304  lineItem->SetLineColor( m_colorSwatch->GetSwatchColor() );
305  m_hasChange = true;
306  }
307  }
308 }
309 
311  SCH_ITEM* aItem )
312 {
313  if( m_selectedFilterOpt->GetValue() && !m_selection.Contains( aItem ) )
314  {
315  return;
316  }
317 
318  if( m_netFilterOpt->GetValue() && !m_netFilter->GetValue().IsEmpty() )
319  {
320  SCH_CONNECTION* connection = aItem->Connection( &aSheetPath );
321 
322  if( !connection )
323  return;
324 
325  if( !WildCompareString( m_netFilter->GetValue(), connection->Name(), false ) )
326  return;
327  }
328 
329  if( m_referenceFilterOpt->GetValue() && !m_referenceFilter->GetValue().IsEmpty() )
330  {
331  if( aItem->Type() == SCH_COMPONENT_T )
332  {
333  wxString ref = static_cast<SCH_COMPONENT*>( aItem )->GetRef( &aSheetPath );
334 
335  if( !WildCompareString( m_referenceFilter->GetValue(), ref, false ) )
336  return;
337  }
338  }
339 
340  if( m_symbolFilterOpt->GetValue() && !m_symbolFilter->GetValue().IsEmpty() )
341  {
342  if( aItem->Type() == SCH_COMPONENT_T )
343  {
344  wxString id = static_cast<SCH_COMPONENT*>( aItem )->GetLibId().Format();
345 
346  if( !WildCompareString( m_symbolFilter->GetValue(), id, false ) )
347  return;
348  }
349  }
350 
351  if( m_typeFilterOpt->GetValue() )
352  {
353  if( aItem->Type() == SCH_COMPONENT_T )
354  {
355  bool isPower = static_cast<SCH_COMPONENT*>( aItem )->GetPartRef()->IsPower();
356 
357  if( isPower != ( m_typeFilter->GetSelection() == 1 ) )
358  return;
359  }
360  }
361 
362  static KICAD_T wireTypes[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LABEL_LOCATE_WIRE_T, EOT };
363  static KICAD_T busTypes[] = { SCH_LINE_LOCATE_BUS_T, SCH_LABEL_LOCATE_BUS_T, EOT };
364  static KICAD_T schTextAndGraphics[] = { SCH_TEXT_T, SCH_LINE_LOCATE_GRAPHIC_LINE_T, EOT };
365 
366  if( aItem->Type() == SCH_COMPONENT_T )
367  {
368  SCH_COMPONENT* component = (SCH_COMPONENT*) aItem;
369 
370  if( m_references->GetValue() )
371  processItem( aSheetPath, component->GetField( REFERENCE_FIELD ) );
372 
373  if( m_values->GetValue() )
374  processItem( aSheetPath, component->GetField( VALUE_FIELD ) );
375 
376  if( m_otherFields->GetValue() )
377  {
378  for( int i = 2; i < component->GetFieldCount(); ++i )
379  {
380  SCH_FIELD& field = component->GetFields()[i];
381  const wxString& fieldName = field.GetName();
382 
383  if( !m_fieldnameFilterOpt->GetValue() || m_fieldnameFilter->GetValue().IsEmpty()
384  || WildCompareString( m_fieldnameFilter->GetValue(), fieldName, false ) )
385  {
386  processItem( aSheetPath, &field );
387  }
388  }
389  }
390  }
391  else if( aItem->Type() == SCH_SHEET_T )
392  {
393  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
394 
395  if( m_sheetTitles->GetValue() )
396  processItem( aSheetPath, &sheet->GetFields()[ SHEETNAME ] );
397 
398  if( m_sheetFields->GetValue() )
399  {
400  for( SCH_FIELD& field : sheet->GetFields() )
401  {
402  if( field.GetId() == SHEETNAME )
403  continue;
404 
405  const wxString& fieldName = field.GetName();
406 
407  if( !m_fieldnameFilterOpt->GetValue() || m_fieldnameFilter->GetValue().IsEmpty()
408  || WildCompareString( m_fieldnameFilter->GetValue(), fieldName, false ) )
409  {
410  processItem( aSheetPath, &field );
411  }
412  }
413  }
414 
415  if( m_sheetBorders->GetValue() )
416  {
418  {
419  sheet->SetBorderWidth( m_lineWidth.GetValue() );
420  m_hasChange = true;
421  }
422 
423  if( m_setColor->GetValue() )
424  {
426  m_hasChange = true;
427  }
428 
429  if( m_setBgColor->GetValue() )
430  {
432  m_hasChange = true;
433  }
434  }
435  }
436  else if( aItem->Type() == SCH_JUNCTION_T )
437  {
438  SCH_JUNCTION* junction = static_cast<SCH_JUNCTION*>( aItem );
439 
440  for( SCH_ITEM* item : junction->ConnectedItems( aSheetPath ) )
441  {
442  if( item->GetLayer() == LAYER_BUS )
443  {
444  if( m_buses->GetValue() && m_setColor->GetValue() )
445  {
446  junction->SetColor( m_colorSwatch->GetSwatchColor() );
447  m_hasChange = true;
448  }
449  break;
450  }
451  else if( item->GetLayer() == LAYER_WIRE )
452  {
453  if( m_wires->GetValue() && m_setColor->GetValue() )
454  {
455  junction->SetColor( m_colorSwatch->GetSwatchColor() );
456  m_hasChange = true;
457  }
458  break;
459  }
460  }
461  }
462  else if( m_wires->GetValue() && aItem->IsType( wireTypes ) )
463  processItem( aSheetPath, aItem );
464  else if( m_buses->GetValue() && aItem->IsType( busTypes ) )
465  processItem( aSheetPath, aItem );
466  else if( m_globalLabels->GetValue() && aItem->Type() == SCH_GLOBAL_LABEL_T )
467  processItem( aSheetPath, aItem );
468  else if( m_hierLabels->GetValue() && aItem->Type() == SCH_HIER_LABEL_T )
469  processItem( aSheetPath, aItem );
470  else if( m_sheetPins->GetValue() && aItem->Type() == SCH_SHEET_PIN_T )
471  processItem( aSheetPath, aItem );
472  else if( m_schTextAndGraphics->GetValue() && aItem->IsType( schTextAndGraphics ) )
473  processItem( aSheetPath, aItem );
474 }
475 
476 
478 {
479  if( !m_textSize.Validate( 1.0, 10000.0, EDA_UNITS::MILS ) ) // 1 mil .. 10 inches
480  return false;
481 
482  SCH_SHEET_PATH currentSheet = m_parent->GetCurrentSheet();
483 
484  // Go through sheets
485  for( const SCH_SHEET_PATH& sheetPath : m_parent->Schematic().GetSheets() )
486  {
487  SCH_SCREEN* screen = sheetPath.LastScreen();
488 
489  if( screen )
490  {
491  m_parent->SetCurrentSheet( sheetPath );
492  m_hasChange = false;
493 
494  for( auto item : screen->Items() )
495  visitItem( sheetPath, item );
496 
497  if( m_hasChange )
498  {
499  m_parent->OnModify();
500  m_parent->HardRedraw();
501  }
502  }
503  }
504 
505  // Reset the view to where we left the user
506  m_parent->SetCurrentSheet( currentSheet );
507 
508  return true;
509 }
510 
511 
513 {
515  dlg.ShowModal();
516  return 0;
517 }
518 
519 
Field Reference of part, i.e. "IC21".
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:51
void SetSwatchColor(KIGFX::COLOR4D aColor, bool aSendEvent)
Set the current swatch color directly.
KIGFX::COLOR4D GetSwatchColor() const
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Returns a mandatory field in this symbol.
Definition: sch_symbol.cpp:687
void RecalculateConnections(SCH_CLEANUP_FLAGS aCleanupFlags)
Generates the connection data for the entire schematic hierarchy.
const SCH_CONNECTION * GetHighlightedConnection() const
void visitItem(const SCH_SHEET_PATH &aSheetPath, SCH_ITEM *aItem)
void SetDefaultColor(KIGFX::COLOR4D aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:270
void SetItalic(bool isItalic)
Definition: eda_text.h:186
void SetColor(const COLOR4D &aColor)
Definition: sch_junction.h:107
void SetVisible(bool aVisible)
Definition: eda_text.h:192
Schematic editor (Eeschema) main window.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
bool IsIndeterminate() const
Return true if the control holds the indeterminate value (for instance, if it represents a multiple s...
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populates a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:723
void SetBorderWidth(int aWidth)
Definition: sch_sheet.h:291
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:131
EE_SELECTION & GetSelection()
Return the set of currently selected items.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:119
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:270
int GlobalEdit(const TOOL_EVENT &aEvent)
Delete the selected items, or the item under the cursor.
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:238
void SetBackgroundColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:297
wxString Name(bool aIgnoreSheet=false) const
Field Value of part, i.e. "3.3K".
static EDA_TEXT_HJUSTIFY_T MapHorizJustify(int aHorizJustify)
Definition: eda_text.cpp:63
void HardRedraw() override
Rebuild the GAL and redraw the screen.
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:499
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:209
Generic, UI-independent tool event.
Definition: tool_event.h:173
bool Contains(EDA_ITEM *aItem) const
Definition: selection.h:114
SCHEMATIC & Schematic() const
void SetBorderColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:294
virtual bool IsType(const KICAD_T aScanTypes[]) const
Check whether the item is one of the listed types.
Definition: eda_item.h:232
void SetLineColor(const COLOR4D &aColor)
Definition: sch_line.cpp:188
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
int GetFieldCount() const
Return the number of fields in this symbol.
Definition: sch_symbol.h:458
static EDA_TEXT_VJUSTIFY_T MapVertJustify(int aVertJustify)
Definition: eda_text.cpp:77
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:219
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:101
static bool m_allowRealTime
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:111
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Validate the control against the given range, informing the user of any errors found.
SCH_SCREEN * LastScreen()
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
SCH_ITEM_SET & ConnectedItems(const SCH_SHEET_PATH &aPath)
Retrieves the set of items connected to this item on the given sheet.
Definition: sch_item.cpp:164
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:208
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend)
Create a copy of the current schematic item, and put it in the undo list.
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:505
EE_RTREE & Items()
Definition: sch_screen.h:162
Schematic symbol object.
Definition: sch_symbol.h:79
void processItem(const SCH_SHEET_PATH &aSheetPath, SCH_ITEM *aItem)
virtual long long int GetValue()
Return the current value in Internal Units.
SCH_SHEET_PATH & GetCurrentSheet() const
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
virtual void SetLabelSpinStyle(LABEL_SPIN_STYLE aSpinStyle)
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:248
#define INDETERMINATE_ACTION
Definition: base_units.h:49
void SetBold(bool aBold)
Definition: eda_text.h:189
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:196
EDA_ITEM * Front() const
Definition: selection.h:203
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:162